170-pcie2-bcma-add-new-PCIe2-driver-for-bcma.patch 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. From cf067bf8bb993d6cfdc42d750ae241c43f88403f Mon Sep 17 00:00:00 2001
  2. From: Hauke Mehrtens <hauke@hauke-m.de>
  3. Date: Mon, 12 May 2014 11:55:20 +0200
  4. Subject: [PATCH 1/2] PCI: BCM5301X: add PCIe2 driver for BCM5301X SoCs
  5. This driver supports the PCIe controller found on the BCM4708 and
  6. similar SoCs. The controller itself is automatically detected by bcma.
  7. This controller is found on SoCs usually used in SOHO routers to
  8. connect the wifi cards to the SoC. All the of the BCM5301X SoCs I know
  9. of have 2 or 3 of these controllers in the SoC.
  10. I had to use PCI domains otherwise the pci_create_root_bus() function
  11. in drivers/pci/probe.c would fail for the second controller being
  12. registered because pci_find_bus() would find the same PCIe bus again
  13. and assume it is already registered, which ends up in a kernel panic in
  14. pcibios_init_hw() in arch/arm/kernel/bios32.c
  15. The ARM PCI code assumes that every controller has an I/O space and
  16. adds a dummy area if the driver does not specify one. This will work
  17. for the first controller, but when we register the second one this will
  18. result in an error. To prevent this problem we add an empty I/O space.
  19. Currently I have problems with probing the devices on the bus, because
  20. pci_bus_add_devices() is called too early in pci_scan_root_bus() in
  21. drivers/pci/probe.c, before pci_bus_assign_resources() was called in
  22. pci_common_init_dev() in arch/arm/kernel/bios32.c. When the devices are
  23. added too early they do not have any resources and adding fails. I have
  24. to remove the call to pci_bus_add_devices() in pci_scan_root_bus() to
  25. make registration work, calling pci_bus_add_devices() later again does
  26. not fix this problem.
  27. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
  28. ---
  29. arch/arm/mach-bcm/Kconfig | 1 +
  30. drivers/pci/host/Kconfig | 7 +
  31. drivers/pci/host/Makefile | 1 +
  32. drivers/pci/host/pci-host-bcm5301x.c | 428 +++++++++++++++++++++++++++++++++++
  33. 4 files changed, 437 insertions(+)
  34. create mode 100644 drivers/pci/host/pci-host-bcm5301x.c
  35. --- a/arch/arm/mach-bcm/Kconfig
  36. +++ b/arch/arm/mach-bcm/Kconfig
  37. @@ -86,6 +86,7 @@ config ARCH_BCM_5301X
  38. select HAVE_ARM_TWD if SMP
  39. select ARM_GLOBAL_TIMER
  40. select CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK
  41. + select PCI_DOMAINS if PCI
  42. help
  43. Support for Broadcom BCM470X and BCM5301X SoCs with ARM CPU cores.
  44. --- a/drivers/pci/host/Kconfig
  45. +++ b/drivers/pci/host/Kconfig
  46. @@ -91,4 +91,11 @@ config PCI_XGENE
  47. There are 5 internal PCIe ports available. Each port is GEN3 capable
  48. and have varied lanes from x1 to x8.
  49. +config PCI_BCM5301X
  50. + bool "BCM5301X PCIe2 host controller"
  51. + depends on BCMA && OF && ARM && PCI_DOMAINS
  52. + help
  53. + Say Y here if you want to support the PCIe host controller found
  54. + on Broadcom BCM5301X and BCM470X (Northstar) SoCs.
  55. +
  56. endmenu
  57. --- a/drivers/pci/host/Makefile
  58. +++ b/drivers/pci/host/Makefile
  59. @@ -11,3 +11,4 @@ obj-$(CONFIG_PCIE_SPEAR13XX) += pcie-spe
  60. obj-$(CONFIG_PCI_KEYSTONE) += pci-keystone-dw.o pci-keystone.o
  61. obj-$(CONFIG_PCIE_XILINX) += pcie-xilinx.o
  62. obj-$(CONFIG_PCI_XGENE) += pci-xgene.o
  63. +obj-$(CONFIG_PCI_BCM5301X) += pci-host-bcm5301x.o
  64. --- /dev/null
  65. +++ b/drivers/pci/host/pci-host-bcm5301x.c
  66. @@ -0,0 +1,461 @@
  67. +/*
  68. + * Northstar PCI-Express driver
  69. + * Only supports Root-Complex (RC) mode
  70. + *
  71. + * Notes:
  72. + * PCI Domains are being used to identify the PCIe port 1:1.
  73. + *
  74. + * Only MEM access is supported, PAX does not support IO.
  75. + *
  76. + * Copyright 2012-2014, Broadcom Corporation
  77. + * Copyright 2014, Hauke Mehrtens <hauke@hauke-m.de>
  78. + *
  79. + * Licensed under the GNU/GPL. See COPYING for details.
  80. + */
  81. +
  82. +#include <linux/kernel.h>
  83. +#include <linux/module.h>
  84. +#include <linux/delay.h>
  85. +#include <linux/pci.h>
  86. +#include <linux/io.h>
  87. +#include <linux/ioport.h>
  88. +#include <linux/bcma/bcma.h>
  89. +#include <linux/bcma/bcma_driver_pcie2.h>
  90. +
  91. +#define SOC_PCIE_HDR_OFF 0x400 /* 256 bytes per function */
  92. +
  93. +#define PCI_LINK_STATUS_CTRL_2_OFFSET 0xDC
  94. +#define PCI_TARGET_LINK_SPEED_MASK 0xF
  95. +#define PCI_TARGET_LINK_SPEED_GEN2 0x2
  96. +#define PCI_TARGET_LINK_SPEED_GEN1 0x1
  97. +
  98. +static int bcma_pcie2_map_irq(const struct pci_dev *pdev, u8 slot, u8 pin)
  99. +{
  100. + struct pci_sys_data *sys = pdev->sysdata;
  101. + struct bcma_device *bdev = sys->private_data;
  102. +
  103. + return bcma_core_irq(bdev, 5);
  104. +}
  105. +
  106. +static u32 bcma_pcie2_cfg_base(struct bcma_device *bdev, int busno,
  107. + unsigned int devfn, int where)
  108. +{
  109. + int slot = PCI_SLOT(devfn);
  110. + int fn = PCI_FUNC(devfn);
  111. + u32 addr_reg;
  112. +
  113. + if (busno == 0) {
  114. + if (slot >= 1)
  115. + return 0;
  116. + bcma_write32(bdev, BCMA_CORE_PCIE2_CONFIGINDADDR,
  117. + where & 0xffc);
  118. + return BCMA_CORE_PCIE2_CONFIGINDDATA;
  119. + }
  120. + if (fn > 1)
  121. + return 0;
  122. + addr_reg = (busno & 0xff) << 20 | (slot << 15) | (fn << 12) |
  123. + (where & 0xffc) | (1 & 0x3);
  124. +
  125. + bcma_write32(bdev, BCMA_CORE_PCIE2_CFG_ADDR, addr_reg);
  126. + return BCMA_CORE_PCIE2_CFG_DATA;
  127. +}
  128. +
  129. +static u32 bcma_pcie2_read_config(struct bcma_device *bdev, int busno,
  130. + unsigned int devfn, int where, int size)
  131. +{
  132. + u32 base;
  133. + u32 data_reg;
  134. + u32 mask;
  135. + int shift;
  136. +
  137. + base = bcma_pcie2_cfg_base(bdev, busno, devfn, where);
  138. +
  139. + if (!base)
  140. + return ~0UL;
  141. +
  142. + data_reg = bcma_read32(bdev, base);
  143. +
  144. + if (size == 4)
  145. + return data_reg;
  146. +
  147. + mask = (1 << (size * 8)) - 1;
  148. + shift = (where % 4) * 8;
  149. + return (data_reg >> shift) & mask;
  150. +}
  151. +
  152. +static void bcma_pcie2_write_config(struct bcma_device *bdev, int busno,
  153. + unsigned int devfn, int where, int size,
  154. + u32 val)
  155. +{
  156. + u32 base;
  157. + u32 data_reg;
  158. +
  159. + base = bcma_pcie2_cfg_base(bdev, busno, devfn, where);
  160. +
  161. + if (!base)
  162. + return;
  163. +
  164. + if (size < 4) {
  165. + u32 mask = (1 << (size * 8)) - 1;
  166. + int shift = (where % 4) * 8;
  167. +
  168. + data_reg = bcma_read32(bdev, base);
  169. + data_reg &= ~(mask << shift);
  170. + data_reg |= (val & mask) << shift;
  171. + } else {
  172. + data_reg = val;
  173. + }
  174. +
  175. + bcma_write32(bdev, base, data_reg);
  176. +}
  177. +
  178. +static int bcma_pcie2_read_config_pci(struct pci_bus *bus, unsigned int devfn,
  179. + int where, int size, u32 *val)
  180. +{
  181. + struct pci_sys_data *sys = bus->sysdata;
  182. + struct bcma_device *bdev = sys->private_data;
  183. +
  184. + *val = bcma_pcie2_read_config(bdev, bus->number, devfn, where, size);
  185. +
  186. + return PCIBIOS_SUCCESSFUL;
  187. +}
  188. +
  189. +static int bcma_pcie2_write_config_pci(struct pci_bus *bus, unsigned int devfn,
  190. + int where, int size, u32 val)
  191. +{
  192. + struct pci_sys_data *sys = bus->sysdata;
  193. + struct bcma_device *bdev = sys->private_data;
  194. +
  195. + bcma_pcie2_write_config(bdev, bus->number, devfn, where, size, val);
  196. +
  197. + return PCIBIOS_SUCCESSFUL;
  198. +}
  199. +
  200. +/*
  201. + * Methods for accessing configuration registers
  202. + */
  203. +static struct pci_ops bcma_pcie2_ops = {
  204. + .read = bcma_pcie2_read_config_pci,
  205. + .write = bcma_pcie2_write_config_pci,
  206. +};
  207. +
  208. +/* NS: CLASS field is R/O, and set to wrong 0x200 value */
  209. +static void bcma_pcie2_fixup_class(struct pci_dev *dev)
  210. +{
  211. + dev->class = PCI_CLASS_BRIDGE_PCI << 8;
  212. +}
  213. +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8011, bcma_pcie2_fixup_class);
  214. +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8012, bcma_pcie2_fixup_class);
  215. +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0xd612, bcma_pcie2_fixup_class);
  216. +
  217. +/*
  218. + * Check link status, return 0 if link is up in RC mode,
  219. + * otherwise return non-zero
  220. + */
  221. +static int bcma_pcie2_check_link(struct bcma_device *bdev, struct pci_sys_data *sys)
  222. +{
  223. + u32 tmp32;
  224. + u16 tmp16;
  225. + u16 pos;
  226. + u8 nlw;
  227. + /*
  228. + * Setup callback (bcma_pcie2_setup) is called in pcibios_init_hw before
  229. + * creating bus root, so we don't have it here yet. On the other hand
  230. + * we really want to use pci_bus_find_capability helper to check NLW.
  231. + * Let's fake simple pci_bus just to query for capabilities.
  232. + */
  233. + struct pci_bus bus = {
  234. + .number = 0,
  235. + .ops = &bcma_pcie2_ops,
  236. + .sysdata = sys,
  237. + };
  238. +
  239. + tmp32 = bcma_read32(bdev, BCMA_CORE_PCIE2_LINK_STATUS);
  240. + dev_dbg(&bdev->dev, "link status: 0x%08x\n", tmp32);
  241. +
  242. + tmp32 = bcma_read32(bdev, BCMA_CORE_PCIE2_STRAP_STATUS);
  243. + dev_dbg(&bdev->dev, "strap status: 0x%08x\n", tmp32);
  244. +
  245. + /* check link status to see if link is active */
  246. + pos = pci_bus_find_capability(&bus, 0, PCI_CAP_ID_EXP);
  247. + pci_bus_read_config_word(&bus, 0, pos + PCI_EXP_LNKSTA, &tmp16);
  248. + nlw = (tmp16 & PCI_EXP_LNKSTA_NLW) >> PCI_EXP_LNKSTA_NLW_SHIFT;
  249. +
  250. + if (nlw == 0) {
  251. + /* try GEN 1 link speed */
  252. + tmp32 = bcma_pcie2_read_config(bdev, 0, 0,
  253. + PCI_LINK_STATUS_CTRL_2_OFFSET, 4);
  254. + if ((tmp32 & PCI_TARGET_LINK_SPEED_MASK) ==
  255. + PCI_TARGET_LINK_SPEED_GEN2) {
  256. + tmp32 &= ~PCI_TARGET_LINK_SPEED_MASK;
  257. + tmp32 |= PCI_TARGET_LINK_SPEED_GEN1;
  258. + bcma_pcie2_write_config(bdev, 0, 0,
  259. + PCI_LINK_STATUS_CTRL_2_OFFSET, 4, tmp32);
  260. + tmp32 = bcma_pcie2_read_config(bdev, 0, 0,
  261. + PCI_LINK_STATUS_CTRL_2_OFFSET, 4);
  262. + msleep(100);
  263. +
  264. + pos = pci_bus_find_capability(&bus, 0, PCI_CAP_ID_EXP);
  265. + pci_bus_read_config_word(&bus, 0, pos + PCI_EXP_LNKSTA,
  266. + &tmp16);
  267. + nlw = (tmp16 & PCI_EXP_LNKSTA_NLW) >>
  268. + PCI_EXP_LNKSTA_NLW_SHIFT;
  269. + }
  270. + }
  271. +
  272. + dev_info(&bdev->dev, "link: %s\n", nlw ? "UP" : "DOWN");
  273. + return nlw ? 0 : -ENODEV;
  274. +}
  275. +
  276. +/*
  277. + * Initializte the PCIe controller
  278. + */
  279. +static void bcma_pcie2_hw_init(struct bcma_device *bdev)
  280. +{
  281. + u32 tmp32;
  282. + u16 tmp16;
  283. +
  284. + /* Change MPS and MRRS to 512 */
  285. + tmp16 = bcma_pcie2_read_config(bdev, 0, 0, 0x4d4, 2);
  286. + tmp16 &= ~7;
  287. + tmp16 |= 2;
  288. + bcma_pcie2_write_config(bdev, 0, 0, 0x4d4, 2, tmp16);
  289. +
  290. + tmp32 = bcma_pcie2_read_config(bdev, 0, 0, 0xb4, 4);
  291. + tmp32 &= ~((7 << 12) | (7 << 5));
  292. + tmp32 |= (2 << 12) | (2 << 5);
  293. + bcma_pcie2_write_config(bdev, 0, 0, 0xb4, 4, tmp32);
  294. +
  295. + /*
  296. + * Turn-on Root-Complex (RC) mode, from reset default of EP
  297. + * The mode is set by straps, can be overwritten via DMU
  298. + * register <cru_straps_control> bit 5, "1" means RC
  299. + */
  300. +
  301. + /* Send a downstream reset */
  302. + bcma_write32(bdev, BCMA_CORE_PCIE2_CLK_CONTROL,
  303. + PCIE2_CLKC_RST_OE | PCIE2_CLKC_RST);
  304. + usleep_range(250, 400);
  305. + bcma_write32(bdev, BCMA_CORE_PCIE2_CLK_CONTROL, PCIE2_CLKC_RST_OE);
  306. + msleep(250);
  307. +
  308. + /* TBD: take care of PM, check we're on */
  309. +}
  310. +
  311. +/*
  312. + * Setup the address translation
  313. + *
  314. + * NOTE: All PCI-to-CPU address mapping are 1:1 for simplicity
  315. + */
  316. +static int bcma_pcie2_map_init(struct bcma_device *bdev, u32 addr)
  317. +{
  318. + /* 64MB alignment */
  319. + if (!addr || (addr & (SZ_64M - 1)))
  320. + return -EINVAL;
  321. +
  322. + bcma_write32(bdev, BCMA_CORE_PCIE2_OMAP0_LOWER, addr);
  323. + bcma_write32(bdev, BCMA_CORE_PCIE2_OARR0, addr | 0x01);
  324. +
  325. + bcma_write32(bdev, BCMA_CORE_PCIE2_OMAP1_LOWER, addr + SZ_64M);
  326. + bcma_write32(bdev, BCMA_CORE_PCIE2_OARR1, (addr + SZ_64M) | 0x01);
  327. +
  328. + /*
  329. + * Inbound address translation setup
  330. + * Northstar only maps up to 128 MiB inbound, DRAM could be up to 1 GiB.
  331. + *
  332. + * For now allow access to entire DRAM, assuming it is less than 128MiB,
  333. + * otherwise DMA bouncing mechanism may be required.
  334. + * Also consider DMA mask to limit DMA physical address
  335. + */
  336. + /* 64-bit LE regs, write low word, high is 0 at reset */
  337. + bcma_write32(bdev, BCMA_CORE_PCIE2_FUNC0_IMAP1, PHYS_OFFSET | 0x1);
  338. + bcma_write32(bdev, BCMA_CORE_PCIE2_IARR1_LOWER,
  339. + PHYS_OFFSET | ((SZ_128M >> 20) & 0xff));
  340. + return 0;
  341. +}
  342. +
  343. +/*
  344. + * Setup PCIE Host bridge
  345. + */
  346. +static int bcma_pcie2_bridge_init(struct bcma_device *bdev, u32 addr, u32 size)
  347. +{
  348. + bcma_pcie2_write_config(bdev, 0, 0, PCI_PRIMARY_BUS, 1, 0);
  349. + bcma_pcie2_write_config(bdev, 0, 0, PCI_SECONDARY_BUS, 1, 1);
  350. + bcma_pcie2_write_config(bdev, 0, 0, PCI_SUBORDINATE_BUS, 1, 4);
  351. +
  352. + bcma_pcie2_read_config(bdev, 0, 0, PCI_PRIMARY_BUS, 1);
  353. + bcma_pcie2_read_config(bdev, 0, 0, PCI_SECONDARY_BUS, 1);
  354. + bcma_pcie2_read_config(bdev, 0, 0, PCI_SUBORDINATE_BUS, 1);
  355. +
  356. + /* MEM_BASE, MEM_LIM require 1MB alignment */
  357. + if (((addr >> 16) & 0xf) || (((addr + size) >> 16) & 0xf))
  358. + return -EINVAL;
  359. +
  360. + bcma_pcie2_write_config(bdev, 0, 0, PCI_MEMORY_BASE, 2, addr >> 16);
  361. + bcma_pcie2_write_config(bdev, 0, 0, PCI_MEMORY_LIMIT, 2,
  362. + (addr + size) >> 16);
  363. +
  364. + /* These registers are not supported on the NS */
  365. + bcma_pcie2_write_config(bdev, 0, 0, PCI_IO_BASE_UPPER16, 2, 0);
  366. + bcma_pcie2_write_config(bdev, 0, 0, PCI_IO_LIMIT_UPPER16, 2, 0);
  367. +
  368. + /* Force class to that of a Bridge */
  369. + bcma_pcie2_write_config(bdev, 0, 0, PCI_CLASS_DEVICE, 2,
  370. + PCI_CLASS_BRIDGE_PCI);
  371. +
  372. + bcma_pcie2_read_config(bdev, 0, 0, PCI_CLASS_DEVICE, 2);
  373. + bcma_pcie2_read_config(bdev, 0, 0, PCI_MEMORY_BASE, 2);
  374. + bcma_pcie2_read_config(bdev, 0, 0, PCI_MEMORY_LIMIT, 2);
  375. + return 0;
  376. +}
  377. +
  378. +static void bcma_pcie2_3rd_init(struct bcma_bus *bus)
  379. +{
  380. + /* PCIE PLL block register (base 0x8000) */
  381. + bcma_chipco_b_mii_write(&bus->drv_cc_b, 0x00000088, 0x57fe8000);
  382. + /* Check PCIE PLL lock status */
  383. + bcma_chipco_b_mii_write(&bus->drv_cc_b, 0x00000088, 0x67c60000);
  384. +}
  385. +
  386. +/* To improve PCIE phy jitter */
  387. +static void bcma_pcie2_improve_phy_jitter(struct bcma_bus *bus, int phyaddr)
  388. +{
  389. + u32 val;
  390. +
  391. + /* Change blkaddr */
  392. + val = (1 << 30) | (1 << 28) | (phyaddr << 23) | (0x1f << 18) |
  393. + (2 << 16) | (0x863 << 4);
  394. + bcma_chipco_b_mii_write(&bus->drv_cc_b, 0x0000009a, val);
  395. +
  396. + /* Write 0x0190 to 0x13 regaddr */
  397. + val = (1 << 30) | (1 << 28) | (phyaddr << 23) | (0x13 << 18) |
  398. + (2 << 16) | 0x0190;
  399. + bcma_chipco_b_mii_write(&bus->drv_cc_b, 0x0000009a, val);
  400. +
  401. + /* Write 0x0191 to 0x19 regaddr */
  402. + val = (1 << 30) | (1 << 28) | (phyaddr << 23) | (0x19 << 18) |
  403. + (2 << 16) | 0x0191;
  404. + bcma_chipco_b_mii_write(&bus->drv_cc_b, 0x0000009a, val);
  405. +}
  406. +
  407. +static int bcma_pcie2_setup(int nr, struct pci_sys_data *sys)
  408. +{
  409. + struct bcma_device *bdev = sys->private_data;
  410. + struct bcma_bus *bus = bdev->bus;
  411. + struct resource *res;
  412. + struct bcma_device *arm_core;
  413. + u32 cru_straps_ctrl;
  414. + int ret;
  415. + int phyaddr;
  416. +
  417. + if (bdev->core_unit == 2) {
  418. + arm_core = bcma_find_core(bus, BCMA_CORE_ARMCA9);
  419. + cru_straps_ctrl = bcma_read32(arm_core, 0x2a0);
  420. +
  421. + /* 3rd PCIE is not selected */
  422. + if (cru_straps_ctrl & 0x10)
  423. + return -ENODEV;
  424. +
  425. + bcma_pcie2_3rd_init(bus);
  426. + phyaddr = 0xf;
  427. + } else {
  428. + phyaddr = bdev->core_unit;
  429. + }
  430. + bcma_pcie2_improve_phy_jitter(bus, phyaddr);
  431. +
  432. + /* create mem resource */
  433. + res = devm_kzalloc(&bdev->dev, sizeof(*res), GFP_KERNEL);
  434. + if (!res)
  435. + return -EINVAL;
  436. +
  437. + res->start = bdev->addr_s[0];
  438. + res->end = bdev->addr_s[0] + SZ_128M -1;
  439. + res->name = "PCIe dummy IO space";
  440. + res->flags = IORESOURCE_MEM;
  441. +
  442. + pci_add_resource(&sys->resources, res);
  443. +
  444. + /* This PCIe controller does not support IO Mem, so use a dummy one. */
  445. + res = devm_kzalloc(&bdev->dev, sizeof(*res), GFP_KERNEL);
  446. + if (!res)
  447. + return -EINVAL;
  448. +
  449. + res->start = 0;
  450. + res->end = 0;
  451. + res->name = "PCIe dummy IO space";
  452. + res->flags = IORESOURCE_IO;
  453. +
  454. + pci_add_resource(&sys->resources, res);
  455. +
  456. + bcma_pcie2_hw_init(bdev);
  457. + ret = bcma_pcie2_map_init(bdev, bdev->addr_s[0]);
  458. + if (ret)
  459. + return ret;
  460. +
  461. + /*
  462. + * Skip inactive ports -
  463. + * will need to change this for hot-plugging
  464. + */
  465. + ret = bcma_pcie2_check_link(bdev, sys);
  466. + if (ret)
  467. + return ret;
  468. +
  469. + ret = bcma_pcie2_bridge_init(bdev, bdev->addr_s[0], SZ_128M);
  470. + if (ret)
  471. + return ret;
  472. +
  473. + return 1;
  474. +}
  475. +
  476. +static int bcma_pcie2_probe(struct bcma_device *bdev)
  477. +{
  478. + struct hw_pci hw = {
  479. + .nr_controllers = 1,
  480. + .domain = bdev->core_unit,
  481. + .private_data = (void **)&bdev,
  482. + .setup = bcma_pcie2_setup,
  483. + .map_irq = bcma_pcie2_map_irq,
  484. + .ops = &bcma_pcie2_ops,
  485. + };
  486. +
  487. + dev_info(&bdev->dev, "initializing PCIe controller\n");
  488. +
  489. + /* Announce this port to ARM/PCI common code */
  490. + pci_common_init_dev(&bdev->dev, &hw);
  491. +
  492. + /* Setup virtual-wire interrupts */
  493. + bcma_write32(bdev, BCMA_CORE_PCIE2_SYS_RC_INTX_EN, 0xf);
  494. +
  495. + /* Enable memory and bus master */
  496. + bcma_write32(bdev, SOC_PCIE_HDR_OFF + 4, 0x6);
  497. +
  498. + return 0;
  499. +}
  500. +
  501. +static const struct bcma_device_id bcma_pcie2_table[] = {
  502. + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_PCIEG2, BCMA_ANY_REV, BCMA_ANY_CLASS),
  503. + BCMA_CORETABLE_END
  504. +};
  505. +MODULE_DEVICE_TABLE(bcma, bcma_pcie2_table);
  506. +
  507. +static struct bcma_driver bcma_pcie2_driver = {
  508. + .name = KBUILD_MODNAME,
  509. + .id_table = bcma_pcie2_table,
  510. + .probe = bcma_pcie2_probe,
  511. +};
  512. +
  513. +static int __init bcma_pcie2_init(void)
  514. +{
  515. + return bcma_driver_register(&bcma_pcie2_driver);
  516. +}
  517. +module_init(bcma_pcie2_init);
  518. +
  519. +static void __exit bcma_pcie2_exit(void)
  520. +{
  521. + bcma_driver_unregister(&bcma_pcie2_driver);
  522. +}
  523. +module_exit(bcma_pcie2_exit);
  524. +
  525. +MODULE_AUTHOR("Hauke Mehrtens");
  526. +MODULE_DESCRIPTION("BCM5301X PCIe host controller");
  527. +MODULE_LICENSE("GPLv2");