pcie-rcar.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * PCIe driver for Renesas R-Car SoCs
  4. * Copyright (C) 2014 Renesas Electronics Europe Ltd
  5. *
  6. * Based on:
  7. * arch/sh/drivers/pci/pcie-sh7786.c
  8. * arch/sh/drivers/pci/ops-sh7786.c
  9. * Copyright (C) 2009 - 2011 Paul Mundt
  10. *
  11. * Author: Phil Edworthy <phil.edworthy@renesas.com>
  12. */
  13. #include <linux/bitops.h>
  14. #include <linux/clk.h>
  15. #include <linux/delay.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/irq.h>
  18. #include <linux/irqdomain.h>
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/msi.h>
  22. #include <linux/of_address.h>
  23. #include <linux/of_irq.h>
  24. #include <linux/of_pci.h>
  25. #include <linux/of_platform.h>
  26. #include <linux/pci.h>
  27. #include <linux/phy/phy.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/pm_runtime.h>
  30. #include <linux/slab.h>
  31. #include "../pci.h"
  32. #define PCIECAR 0x000010
  33. #define PCIECCTLR 0x000018
  34. #define CONFIG_SEND_ENABLE BIT(31)
  35. #define TYPE0 (0 << 8)
  36. #define TYPE1 BIT(8)
  37. #define PCIECDR 0x000020
  38. #define PCIEMSR 0x000028
  39. #define PCIEINTXR 0x000400
  40. #define PCIEPHYSR 0x0007f0
  41. #define PHYRDY BIT(0)
  42. #define PCIEMSITXR 0x000840
  43. /* Transfer control */
  44. #define PCIETCTLR 0x02000
  45. #define CFINIT 1
  46. #define PCIETSTR 0x02004
  47. #define DATA_LINK_ACTIVE 1
  48. #define PCIEERRFR 0x02020
  49. #define UNSUPPORTED_REQUEST BIT(4)
  50. #define PCIEMSIFR 0x02044
  51. #define PCIEMSIALR 0x02048
  52. #define MSIFE 1
  53. #define PCIEMSIAUR 0x0204c
  54. #define PCIEMSIIER 0x02050
  55. /* root port address */
  56. #define PCIEPRAR(x) (0x02080 + ((x) * 0x4))
  57. /* local address reg & mask */
  58. #define PCIELAR(x) (0x02200 + ((x) * 0x20))
  59. #define PCIELAMR(x) (0x02208 + ((x) * 0x20))
  60. #define LAM_PREFETCH BIT(3)
  61. #define LAM_64BIT BIT(2)
  62. #define LAR_ENABLE BIT(1)
  63. /* PCIe address reg & mask */
  64. #define PCIEPALR(x) (0x03400 + ((x) * 0x20))
  65. #define PCIEPAUR(x) (0x03404 + ((x) * 0x20))
  66. #define PCIEPAMR(x) (0x03408 + ((x) * 0x20))
  67. #define PCIEPTCTLR(x) (0x0340c + ((x) * 0x20))
  68. #define PAR_ENABLE BIT(31)
  69. #define IO_SPACE BIT(8)
  70. /* Configuration */
  71. #define PCICONF(x) (0x010000 + ((x) * 0x4))
  72. #define PMCAP(x) (0x010040 + ((x) * 0x4))
  73. #define EXPCAP(x) (0x010070 + ((x) * 0x4))
  74. #define VCCAP(x) (0x010100 + ((x) * 0x4))
  75. /* link layer */
  76. #define IDSETR1 0x011004
  77. #define TLCTLR 0x011048
  78. #define MACSR 0x011054
  79. #define SPCHGFIN BIT(4)
  80. #define SPCHGFAIL BIT(6)
  81. #define SPCHGSUC BIT(7)
  82. #define LINK_SPEED (0xf << 16)
  83. #define LINK_SPEED_2_5GTS (1 << 16)
  84. #define LINK_SPEED_5_0GTS (2 << 16)
  85. #define MACCTLR 0x011058
  86. #define SPEED_CHANGE BIT(24)
  87. #define SCRAMBLE_DISABLE BIT(27)
  88. #define MACS2R 0x011078
  89. #define MACCGSPSETR 0x011084
  90. #define SPCNGRSN BIT(31)
  91. /* R-Car H1 PHY */
  92. #define H1_PCIEPHYADRR 0x04000c
  93. #define WRITE_CMD BIT(16)
  94. #define PHY_ACK BIT(24)
  95. #define RATE_POS 12
  96. #define LANE_POS 8
  97. #define ADR_POS 0
  98. #define H1_PCIEPHYDOUTR 0x040014
  99. /* R-Car Gen2 PHY */
  100. #define GEN2_PCIEPHYADDR 0x780
  101. #define GEN2_PCIEPHYDATA 0x784
  102. #define GEN2_PCIEPHYCTRL 0x78c
  103. #define INT_PCI_MSI_NR 32
  104. #define RCONF(x) (PCICONF(0) + (x))
  105. #define RPMCAP(x) (PMCAP(0) + (x))
  106. #define REXPCAP(x) (EXPCAP(0) + (x))
  107. #define RVCCAP(x) (VCCAP(0) + (x))
  108. #define PCIE_CONF_BUS(b) (((b) & 0xff) << 24)
  109. #define PCIE_CONF_DEV(d) (((d) & 0x1f) << 19)
  110. #define PCIE_CONF_FUNC(f) (((f) & 0x7) << 16)
  111. #define RCAR_PCI_MAX_RESOURCES 4
  112. #define MAX_NR_INBOUND_MAPS 6
  113. struct rcar_msi {
  114. DECLARE_BITMAP(used, INT_PCI_MSI_NR);
  115. struct irq_domain *domain;
  116. struct msi_controller chip;
  117. unsigned long pages;
  118. struct mutex lock;
  119. int irq1;
  120. int irq2;
  121. };
  122. static inline struct rcar_msi *to_rcar_msi(struct msi_controller *chip)
  123. {
  124. return container_of(chip, struct rcar_msi, chip);
  125. }
  126. /* Structure representing the PCIe interface */
  127. struct rcar_pcie {
  128. struct device *dev;
  129. struct phy *phy;
  130. void __iomem *base;
  131. struct list_head resources;
  132. int root_bus_nr;
  133. struct clk *bus_clk;
  134. struct rcar_msi msi;
  135. };
  136. static void rcar_pci_write_reg(struct rcar_pcie *pcie, unsigned long val,
  137. unsigned long reg)
  138. {
  139. writel(val, pcie->base + reg);
  140. }
  141. static unsigned long rcar_pci_read_reg(struct rcar_pcie *pcie,
  142. unsigned long reg)
  143. {
  144. return readl(pcie->base + reg);
  145. }
  146. enum {
  147. RCAR_PCI_ACCESS_READ,
  148. RCAR_PCI_ACCESS_WRITE,
  149. };
  150. static void rcar_rmw32(struct rcar_pcie *pcie, int where, u32 mask, u32 data)
  151. {
  152. int shift = 8 * (where & 3);
  153. u32 val = rcar_pci_read_reg(pcie, where & ~3);
  154. val &= ~(mask << shift);
  155. val |= data << shift;
  156. rcar_pci_write_reg(pcie, val, where & ~3);
  157. }
  158. static u32 rcar_read_conf(struct rcar_pcie *pcie, int where)
  159. {
  160. int shift = 8 * (where & 3);
  161. u32 val = rcar_pci_read_reg(pcie, where & ~3);
  162. return val >> shift;
  163. }
  164. /* Serialization is provided by 'pci_lock' in drivers/pci/access.c */
  165. static int rcar_pcie_config_access(struct rcar_pcie *pcie,
  166. unsigned char access_type, struct pci_bus *bus,
  167. unsigned int devfn, int where, u32 *data)
  168. {
  169. int dev, func, reg, index;
  170. dev = PCI_SLOT(devfn);
  171. func = PCI_FUNC(devfn);
  172. reg = where & ~3;
  173. index = reg / 4;
  174. /*
  175. * While each channel has its own memory-mapped extended config
  176. * space, it's generally only accessible when in endpoint mode.
  177. * When in root complex mode, the controller is unable to target
  178. * itself with either type 0 or type 1 accesses, and indeed, any
  179. * controller initiated target transfer to its own config space
  180. * result in a completer abort.
  181. *
  182. * Each channel effectively only supports a single device, but as
  183. * the same channel <-> device access works for any PCI_SLOT()
  184. * value, we cheat a bit here and bind the controller's config
  185. * space to devfn 0 in order to enable self-enumeration. In this
  186. * case the regular ECAR/ECDR path is sidelined and the mangled
  187. * config access itself is initiated as an internal bus transaction.
  188. */
  189. if (pci_is_root_bus(bus)) {
  190. if (dev != 0)
  191. return PCIBIOS_DEVICE_NOT_FOUND;
  192. if (access_type == RCAR_PCI_ACCESS_READ) {
  193. *data = rcar_pci_read_reg(pcie, PCICONF(index));
  194. } else {
  195. /* Keep an eye out for changes to the root bus number */
  196. if (pci_is_root_bus(bus) && (reg == PCI_PRIMARY_BUS))
  197. pcie->root_bus_nr = *data & 0xff;
  198. rcar_pci_write_reg(pcie, *data, PCICONF(index));
  199. }
  200. return PCIBIOS_SUCCESSFUL;
  201. }
  202. if (pcie->root_bus_nr < 0)
  203. return PCIBIOS_DEVICE_NOT_FOUND;
  204. /* Clear errors */
  205. rcar_pci_write_reg(pcie, rcar_pci_read_reg(pcie, PCIEERRFR), PCIEERRFR);
  206. /* Set the PIO address */
  207. rcar_pci_write_reg(pcie, PCIE_CONF_BUS(bus->number) |
  208. PCIE_CONF_DEV(dev) | PCIE_CONF_FUNC(func) | reg, PCIECAR);
  209. /* Enable the configuration access */
  210. if (bus->parent->number == pcie->root_bus_nr)
  211. rcar_pci_write_reg(pcie, CONFIG_SEND_ENABLE | TYPE0, PCIECCTLR);
  212. else
  213. rcar_pci_write_reg(pcie, CONFIG_SEND_ENABLE | TYPE1, PCIECCTLR);
  214. /* Check for errors */
  215. if (rcar_pci_read_reg(pcie, PCIEERRFR) & UNSUPPORTED_REQUEST)
  216. return PCIBIOS_DEVICE_NOT_FOUND;
  217. /* Check for master and target aborts */
  218. if (rcar_read_conf(pcie, RCONF(PCI_STATUS)) &
  219. (PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT))
  220. return PCIBIOS_DEVICE_NOT_FOUND;
  221. if (access_type == RCAR_PCI_ACCESS_READ)
  222. *data = rcar_pci_read_reg(pcie, PCIECDR);
  223. else
  224. rcar_pci_write_reg(pcie, *data, PCIECDR);
  225. /* Disable the configuration access */
  226. rcar_pci_write_reg(pcie, 0, PCIECCTLR);
  227. return PCIBIOS_SUCCESSFUL;
  228. }
  229. static int rcar_pcie_read_conf(struct pci_bus *bus, unsigned int devfn,
  230. int where, int size, u32 *val)
  231. {
  232. struct rcar_pcie *pcie = bus->sysdata;
  233. int ret;
  234. ret = rcar_pcie_config_access(pcie, RCAR_PCI_ACCESS_READ,
  235. bus, devfn, where, val);
  236. if (ret != PCIBIOS_SUCCESSFUL) {
  237. *val = 0xffffffff;
  238. return ret;
  239. }
  240. if (size == 1)
  241. *val = (*val >> (8 * (where & 3))) & 0xff;
  242. else if (size == 2)
  243. *val = (*val >> (8 * (where & 2))) & 0xffff;
  244. dev_dbg(&bus->dev, "pcie-config-read: bus=%3d devfn=0x%04x where=0x%04x size=%d val=0x%08lx\n",
  245. bus->number, devfn, where, size, (unsigned long)*val);
  246. return ret;
  247. }
  248. /* Serialization is provided by 'pci_lock' in drivers/pci/access.c */
  249. static int rcar_pcie_write_conf(struct pci_bus *bus, unsigned int devfn,
  250. int where, int size, u32 val)
  251. {
  252. struct rcar_pcie *pcie = bus->sysdata;
  253. int shift, ret;
  254. u32 data;
  255. ret = rcar_pcie_config_access(pcie, RCAR_PCI_ACCESS_READ,
  256. bus, devfn, where, &data);
  257. if (ret != PCIBIOS_SUCCESSFUL)
  258. return ret;
  259. dev_dbg(&bus->dev, "pcie-config-write: bus=%3d devfn=0x%04x where=0x%04x size=%d val=0x%08lx\n",
  260. bus->number, devfn, where, size, (unsigned long)val);
  261. if (size == 1) {
  262. shift = 8 * (where & 3);
  263. data &= ~(0xff << shift);
  264. data |= ((val & 0xff) << shift);
  265. } else if (size == 2) {
  266. shift = 8 * (where & 2);
  267. data &= ~(0xffff << shift);
  268. data |= ((val & 0xffff) << shift);
  269. } else
  270. data = val;
  271. ret = rcar_pcie_config_access(pcie, RCAR_PCI_ACCESS_WRITE,
  272. bus, devfn, where, &data);
  273. return ret;
  274. }
  275. static struct pci_ops rcar_pcie_ops = {
  276. .read = rcar_pcie_read_conf,
  277. .write = rcar_pcie_write_conf,
  278. };
  279. static void rcar_pcie_setup_window(int win, struct rcar_pcie *pcie,
  280. struct resource *res)
  281. {
  282. /* Setup PCIe address space mappings for each resource */
  283. resource_size_t size;
  284. resource_size_t res_start;
  285. u32 mask;
  286. rcar_pci_write_reg(pcie, 0x00000000, PCIEPTCTLR(win));
  287. /*
  288. * The PAMR mask is calculated in units of 128Bytes, which
  289. * keeps things pretty simple.
  290. */
  291. size = resource_size(res);
  292. mask = (roundup_pow_of_two(size) / SZ_128) - 1;
  293. rcar_pci_write_reg(pcie, mask << 7, PCIEPAMR(win));
  294. if (res->flags & IORESOURCE_IO)
  295. res_start = pci_pio_to_address(res->start);
  296. else
  297. res_start = res->start;
  298. rcar_pci_write_reg(pcie, upper_32_bits(res_start), PCIEPAUR(win));
  299. rcar_pci_write_reg(pcie, lower_32_bits(res_start) & ~0x7F,
  300. PCIEPALR(win));
  301. /* First resource is for IO */
  302. mask = PAR_ENABLE;
  303. if (res->flags & IORESOURCE_IO)
  304. mask |= IO_SPACE;
  305. rcar_pci_write_reg(pcie, mask, PCIEPTCTLR(win));
  306. }
  307. static int rcar_pcie_setup(struct list_head *resource, struct rcar_pcie *pci)
  308. {
  309. struct resource_entry *win;
  310. int i = 0;
  311. /* Setup PCI resources */
  312. resource_list_for_each_entry(win, &pci->resources) {
  313. struct resource *res = win->res;
  314. if (!res->flags)
  315. continue;
  316. switch (resource_type(res)) {
  317. case IORESOURCE_IO:
  318. case IORESOURCE_MEM:
  319. rcar_pcie_setup_window(i, pci, res);
  320. i++;
  321. break;
  322. case IORESOURCE_BUS:
  323. pci->root_bus_nr = res->start;
  324. break;
  325. default:
  326. continue;
  327. }
  328. pci_add_resource(resource, res);
  329. }
  330. return 1;
  331. }
  332. static void rcar_pcie_force_speedup(struct rcar_pcie *pcie)
  333. {
  334. struct device *dev = pcie->dev;
  335. unsigned int timeout = 1000;
  336. u32 macsr;
  337. if ((rcar_pci_read_reg(pcie, MACS2R) & LINK_SPEED) != LINK_SPEED_5_0GTS)
  338. return;
  339. if (rcar_pci_read_reg(pcie, MACCTLR) & SPEED_CHANGE) {
  340. dev_err(dev, "Speed change already in progress\n");
  341. return;
  342. }
  343. macsr = rcar_pci_read_reg(pcie, MACSR);
  344. if ((macsr & LINK_SPEED) == LINK_SPEED_5_0GTS)
  345. goto done;
  346. /* Set target link speed to 5.0 GT/s */
  347. rcar_rmw32(pcie, EXPCAP(12), PCI_EXP_LNKSTA_CLS,
  348. PCI_EXP_LNKSTA_CLS_5_0GB);
  349. /* Set speed change reason as intentional factor */
  350. rcar_rmw32(pcie, MACCGSPSETR, SPCNGRSN, 0);
  351. /* Clear SPCHGFIN, SPCHGSUC, and SPCHGFAIL */
  352. if (macsr & (SPCHGFIN | SPCHGSUC | SPCHGFAIL))
  353. rcar_pci_write_reg(pcie, macsr, MACSR);
  354. /* Start link speed change */
  355. rcar_rmw32(pcie, MACCTLR, SPEED_CHANGE, SPEED_CHANGE);
  356. while (timeout--) {
  357. macsr = rcar_pci_read_reg(pcie, MACSR);
  358. if (macsr & SPCHGFIN) {
  359. /* Clear the interrupt bits */
  360. rcar_pci_write_reg(pcie, macsr, MACSR);
  361. if (macsr & SPCHGFAIL)
  362. dev_err(dev, "Speed change failed\n");
  363. goto done;
  364. }
  365. msleep(1);
  366. }
  367. dev_err(dev, "Speed change timed out\n");
  368. done:
  369. dev_info(dev, "Current link speed is %s GT/s\n",
  370. (macsr & LINK_SPEED) == LINK_SPEED_5_0GTS ? "5" : "2.5");
  371. }
  372. static int rcar_pcie_enable(struct rcar_pcie *pcie)
  373. {
  374. struct device *dev = pcie->dev;
  375. struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
  376. struct pci_bus *bus, *child;
  377. int ret;
  378. /* Try setting 5 GT/s link speed */
  379. rcar_pcie_force_speedup(pcie);
  380. rcar_pcie_setup(&bridge->windows, pcie);
  381. pci_add_flags(PCI_REASSIGN_ALL_BUS);
  382. bridge->dev.parent = dev;
  383. bridge->sysdata = pcie;
  384. bridge->busnr = pcie->root_bus_nr;
  385. bridge->ops = &rcar_pcie_ops;
  386. bridge->map_irq = of_irq_parse_and_map_pci;
  387. bridge->swizzle_irq = pci_common_swizzle;
  388. if (IS_ENABLED(CONFIG_PCI_MSI))
  389. bridge->msi = &pcie->msi.chip;
  390. ret = pci_scan_root_bus_bridge(bridge);
  391. if (ret < 0)
  392. return ret;
  393. bus = bridge->bus;
  394. pci_bus_size_bridges(bus);
  395. pci_bus_assign_resources(bus);
  396. list_for_each_entry(child, &bus->children, node)
  397. pcie_bus_configure_settings(child);
  398. pci_bus_add_devices(bus);
  399. return 0;
  400. }
  401. static int phy_wait_for_ack(struct rcar_pcie *pcie)
  402. {
  403. struct device *dev = pcie->dev;
  404. unsigned int timeout = 100;
  405. while (timeout--) {
  406. if (rcar_pci_read_reg(pcie, H1_PCIEPHYADRR) & PHY_ACK)
  407. return 0;
  408. udelay(100);
  409. }
  410. dev_err(dev, "Access to PCIe phy timed out\n");
  411. return -ETIMEDOUT;
  412. }
  413. static void phy_write_reg(struct rcar_pcie *pcie,
  414. unsigned int rate, unsigned int addr,
  415. unsigned int lane, unsigned int data)
  416. {
  417. unsigned long phyaddr;
  418. phyaddr = WRITE_CMD |
  419. ((rate & 1) << RATE_POS) |
  420. ((lane & 0xf) << LANE_POS) |
  421. ((addr & 0xff) << ADR_POS);
  422. /* Set write data */
  423. rcar_pci_write_reg(pcie, data, H1_PCIEPHYDOUTR);
  424. rcar_pci_write_reg(pcie, phyaddr, H1_PCIEPHYADRR);
  425. /* Ignore errors as they will be dealt with if the data link is down */
  426. phy_wait_for_ack(pcie);
  427. /* Clear command */
  428. rcar_pci_write_reg(pcie, 0, H1_PCIEPHYDOUTR);
  429. rcar_pci_write_reg(pcie, 0, H1_PCIEPHYADRR);
  430. /* Ignore errors as they will be dealt with if the data link is down */
  431. phy_wait_for_ack(pcie);
  432. }
  433. static int rcar_pcie_wait_for_phyrdy(struct rcar_pcie *pcie)
  434. {
  435. unsigned int timeout = 10;
  436. while (timeout--) {
  437. if (rcar_pci_read_reg(pcie, PCIEPHYSR) & PHYRDY)
  438. return 0;
  439. msleep(5);
  440. }
  441. return -ETIMEDOUT;
  442. }
  443. static int rcar_pcie_wait_for_dl(struct rcar_pcie *pcie)
  444. {
  445. unsigned int timeout = 10000;
  446. while (timeout--) {
  447. if ((rcar_pci_read_reg(pcie, PCIETSTR) & DATA_LINK_ACTIVE))
  448. return 0;
  449. udelay(5);
  450. cpu_relax();
  451. }
  452. return -ETIMEDOUT;
  453. }
  454. static int rcar_pcie_hw_init(struct rcar_pcie *pcie)
  455. {
  456. int err;
  457. /* Begin initialization */
  458. rcar_pci_write_reg(pcie, 0, PCIETCTLR);
  459. /* Set mode */
  460. rcar_pci_write_reg(pcie, 1, PCIEMSR);
  461. err = rcar_pcie_wait_for_phyrdy(pcie);
  462. if (err)
  463. return err;
  464. /*
  465. * Initial header for port config space is type 1, set the device
  466. * class to match. Hardware takes care of propagating the IDSETR
  467. * settings, so there is no need to bother with a quirk.
  468. */
  469. rcar_pci_write_reg(pcie, PCI_CLASS_BRIDGE_PCI << 16, IDSETR1);
  470. /*
  471. * Setup Secondary Bus Number & Subordinate Bus Number, even though
  472. * they aren't used, to avoid bridge being detected as broken.
  473. */
  474. rcar_rmw32(pcie, RCONF(PCI_SECONDARY_BUS), 0xff, 1);
  475. rcar_rmw32(pcie, RCONF(PCI_SUBORDINATE_BUS), 0xff, 1);
  476. /* Initialize default capabilities. */
  477. rcar_rmw32(pcie, REXPCAP(0), 0xff, PCI_CAP_ID_EXP);
  478. rcar_rmw32(pcie, REXPCAP(PCI_EXP_FLAGS),
  479. PCI_EXP_FLAGS_TYPE, PCI_EXP_TYPE_ROOT_PORT << 4);
  480. rcar_rmw32(pcie, RCONF(PCI_HEADER_TYPE), 0x7f,
  481. PCI_HEADER_TYPE_BRIDGE);
  482. /* Enable data link layer active state reporting */
  483. rcar_rmw32(pcie, REXPCAP(PCI_EXP_LNKCAP), PCI_EXP_LNKCAP_DLLLARC,
  484. PCI_EXP_LNKCAP_DLLLARC);
  485. /* Write out the physical slot number = 0 */
  486. rcar_rmw32(pcie, REXPCAP(PCI_EXP_SLTCAP), PCI_EXP_SLTCAP_PSN, 0);
  487. /* Set the completion timer timeout to the maximum 50ms. */
  488. rcar_rmw32(pcie, TLCTLR + 1, 0x3f, 50);
  489. /* Terminate list of capabilities (Next Capability Offset=0) */
  490. rcar_rmw32(pcie, RVCCAP(0), 0xfff00000, 0);
  491. /* Enable MSI */
  492. if (IS_ENABLED(CONFIG_PCI_MSI))
  493. rcar_pci_write_reg(pcie, 0x801f0000, PCIEMSITXR);
  494. /* Finish initialization - establish a PCI Express link */
  495. rcar_pci_write_reg(pcie, CFINIT, PCIETCTLR);
  496. /* This will timeout if we don't have a link. */
  497. err = rcar_pcie_wait_for_dl(pcie);
  498. if (err)
  499. return err;
  500. /* Enable INTx interrupts */
  501. rcar_rmw32(pcie, PCIEINTXR, 0, 0xF << 8);
  502. wmb();
  503. return 0;
  504. }
  505. static int rcar_pcie_phy_init_h1(struct rcar_pcie *pcie)
  506. {
  507. /* Initialize the phy */
  508. phy_write_reg(pcie, 0, 0x42, 0x1, 0x0EC34191);
  509. phy_write_reg(pcie, 1, 0x42, 0x1, 0x0EC34180);
  510. phy_write_reg(pcie, 0, 0x43, 0x1, 0x00210188);
  511. phy_write_reg(pcie, 1, 0x43, 0x1, 0x00210188);
  512. phy_write_reg(pcie, 0, 0x44, 0x1, 0x015C0014);
  513. phy_write_reg(pcie, 1, 0x44, 0x1, 0x015C0014);
  514. phy_write_reg(pcie, 1, 0x4C, 0x1, 0x786174A0);
  515. phy_write_reg(pcie, 1, 0x4D, 0x1, 0x048000BB);
  516. phy_write_reg(pcie, 0, 0x51, 0x1, 0x079EC062);
  517. phy_write_reg(pcie, 0, 0x52, 0x1, 0x20000000);
  518. phy_write_reg(pcie, 1, 0x52, 0x1, 0x20000000);
  519. phy_write_reg(pcie, 1, 0x56, 0x1, 0x00003806);
  520. phy_write_reg(pcie, 0, 0x60, 0x1, 0x004B03A5);
  521. phy_write_reg(pcie, 0, 0x64, 0x1, 0x3F0F1F0F);
  522. phy_write_reg(pcie, 0, 0x66, 0x1, 0x00008000);
  523. return 0;
  524. }
  525. static int rcar_pcie_phy_init_gen2(struct rcar_pcie *pcie)
  526. {
  527. /*
  528. * These settings come from the R-Car Series, 2nd Generation User's
  529. * Manual, section 50.3.1 (2) Initialization of the physical layer.
  530. */
  531. rcar_pci_write_reg(pcie, 0x000f0030, GEN2_PCIEPHYADDR);
  532. rcar_pci_write_reg(pcie, 0x00381203, GEN2_PCIEPHYDATA);
  533. rcar_pci_write_reg(pcie, 0x00000001, GEN2_PCIEPHYCTRL);
  534. rcar_pci_write_reg(pcie, 0x00000006, GEN2_PCIEPHYCTRL);
  535. rcar_pci_write_reg(pcie, 0x000f0054, GEN2_PCIEPHYADDR);
  536. /* The following value is for DC connection, no termination resistor */
  537. rcar_pci_write_reg(pcie, 0x13802007, GEN2_PCIEPHYDATA);
  538. rcar_pci_write_reg(pcie, 0x00000001, GEN2_PCIEPHYCTRL);
  539. rcar_pci_write_reg(pcie, 0x00000006, GEN2_PCIEPHYCTRL);
  540. return 0;
  541. }
  542. static int rcar_pcie_phy_init_gen3(struct rcar_pcie *pcie)
  543. {
  544. int err;
  545. err = phy_init(pcie->phy);
  546. if (err)
  547. return err;
  548. return phy_power_on(pcie->phy);
  549. }
  550. static int rcar_msi_alloc(struct rcar_msi *chip)
  551. {
  552. int msi;
  553. mutex_lock(&chip->lock);
  554. msi = find_first_zero_bit(chip->used, INT_PCI_MSI_NR);
  555. if (msi < INT_PCI_MSI_NR)
  556. set_bit(msi, chip->used);
  557. else
  558. msi = -ENOSPC;
  559. mutex_unlock(&chip->lock);
  560. return msi;
  561. }
  562. static int rcar_msi_alloc_region(struct rcar_msi *chip, int no_irqs)
  563. {
  564. int msi;
  565. mutex_lock(&chip->lock);
  566. msi = bitmap_find_free_region(chip->used, INT_PCI_MSI_NR,
  567. order_base_2(no_irqs));
  568. mutex_unlock(&chip->lock);
  569. return msi;
  570. }
  571. static void rcar_msi_free(struct rcar_msi *chip, unsigned long irq)
  572. {
  573. mutex_lock(&chip->lock);
  574. clear_bit(irq, chip->used);
  575. mutex_unlock(&chip->lock);
  576. }
  577. static irqreturn_t rcar_pcie_msi_irq(int irq, void *data)
  578. {
  579. struct rcar_pcie *pcie = data;
  580. struct rcar_msi *msi = &pcie->msi;
  581. struct device *dev = pcie->dev;
  582. unsigned long reg;
  583. reg = rcar_pci_read_reg(pcie, PCIEMSIFR);
  584. /* MSI & INTx share an interrupt - we only handle MSI here */
  585. if (!reg)
  586. return IRQ_NONE;
  587. while (reg) {
  588. unsigned int index = find_first_bit(&reg, 32);
  589. unsigned int irq;
  590. /* clear the interrupt */
  591. rcar_pci_write_reg(pcie, 1 << index, PCIEMSIFR);
  592. irq = irq_find_mapping(msi->domain, index);
  593. if (irq) {
  594. if (test_bit(index, msi->used))
  595. generic_handle_irq(irq);
  596. else
  597. dev_info(dev, "unhandled MSI\n");
  598. } else {
  599. /* Unknown MSI, just clear it */
  600. dev_dbg(dev, "unexpected MSI\n");
  601. }
  602. /* see if there's any more pending in this vector */
  603. reg = rcar_pci_read_reg(pcie, PCIEMSIFR);
  604. }
  605. return IRQ_HANDLED;
  606. }
  607. static int rcar_msi_setup_irq(struct msi_controller *chip, struct pci_dev *pdev,
  608. struct msi_desc *desc)
  609. {
  610. struct rcar_msi *msi = to_rcar_msi(chip);
  611. struct rcar_pcie *pcie = container_of(chip, struct rcar_pcie, msi.chip);
  612. struct msi_msg msg;
  613. unsigned int irq;
  614. int hwirq;
  615. hwirq = rcar_msi_alloc(msi);
  616. if (hwirq < 0)
  617. return hwirq;
  618. irq = irq_find_mapping(msi->domain, hwirq);
  619. if (!irq) {
  620. rcar_msi_free(msi, hwirq);
  621. return -EINVAL;
  622. }
  623. irq_set_msi_desc(irq, desc);
  624. msg.address_lo = rcar_pci_read_reg(pcie, PCIEMSIALR) & ~MSIFE;
  625. msg.address_hi = rcar_pci_read_reg(pcie, PCIEMSIAUR);
  626. msg.data = hwirq;
  627. pci_write_msi_msg(irq, &msg);
  628. return 0;
  629. }
  630. static int rcar_msi_setup_irqs(struct msi_controller *chip,
  631. struct pci_dev *pdev, int nvec, int type)
  632. {
  633. struct rcar_pcie *pcie = container_of(chip, struct rcar_pcie, msi.chip);
  634. struct rcar_msi *msi = to_rcar_msi(chip);
  635. struct msi_desc *desc;
  636. struct msi_msg msg;
  637. unsigned int irq;
  638. int hwirq;
  639. int i;
  640. /* MSI-X interrupts are not supported */
  641. if (type == PCI_CAP_ID_MSIX)
  642. return -EINVAL;
  643. WARN_ON(!list_is_singular(&pdev->dev.msi_list));
  644. desc = list_entry(pdev->dev.msi_list.next, struct msi_desc, list);
  645. hwirq = rcar_msi_alloc_region(msi, nvec);
  646. if (hwirq < 0)
  647. return -ENOSPC;
  648. irq = irq_find_mapping(msi->domain, hwirq);
  649. if (!irq)
  650. return -ENOSPC;
  651. for (i = 0; i < nvec; i++) {
  652. /*
  653. * irq_create_mapping() called from rcar_pcie_probe() pre-
  654. * allocates descs, so there is no need to allocate descs here.
  655. * We can therefore assume that if irq_find_mapping() above
  656. * returns non-zero, then the descs are also successfully
  657. * allocated.
  658. */
  659. if (irq_set_msi_desc_off(irq, i, desc)) {
  660. /* TODO: clear */
  661. return -EINVAL;
  662. }
  663. }
  664. desc->nvec_used = nvec;
  665. desc->msi_attrib.multiple = order_base_2(nvec);
  666. msg.address_lo = rcar_pci_read_reg(pcie, PCIEMSIALR) & ~MSIFE;
  667. msg.address_hi = rcar_pci_read_reg(pcie, PCIEMSIAUR);
  668. msg.data = hwirq;
  669. pci_write_msi_msg(irq, &msg);
  670. return 0;
  671. }
  672. static void rcar_msi_teardown_irq(struct msi_controller *chip, unsigned int irq)
  673. {
  674. struct rcar_msi *msi = to_rcar_msi(chip);
  675. struct irq_data *d = irq_get_irq_data(irq);
  676. rcar_msi_free(msi, d->hwirq);
  677. }
  678. static struct irq_chip rcar_msi_irq_chip = {
  679. .name = "R-Car PCIe MSI",
  680. .irq_enable = pci_msi_unmask_irq,
  681. .irq_disable = pci_msi_mask_irq,
  682. .irq_mask = pci_msi_mask_irq,
  683. .irq_unmask = pci_msi_unmask_irq,
  684. };
  685. static int rcar_msi_map(struct irq_domain *domain, unsigned int irq,
  686. irq_hw_number_t hwirq)
  687. {
  688. irq_set_chip_and_handler(irq, &rcar_msi_irq_chip, handle_simple_irq);
  689. irq_set_chip_data(irq, domain->host_data);
  690. return 0;
  691. }
  692. static const struct irq_domain_ops msi_domain_ops = {
  693. .map = rcar_msi_map,
  694. };
  695. static void rcar_pcie_unmap_msi(struct rcar_pcie *pcie)
  696. {
  697. struct rcar_msi *msi = &pcie->msi;
  698. int i, irq;
  699. for (i = 0; i < INT_PCI_MSI_NR; i++) {
  700. irq = irq_find_mapping(msi->domain, i);
  701. if (irq > 0)
  702. irq_dispose_mapping(irq);
  703. }
  704. irq_domain_remove(msi->domain);
  705. }
  706. static int rcar_pcie_enable_msi(struct rcar_pcie *pcie)
  707. {
  708. struct device *dev = pcie->dev;
  709. struct rcar_msi *msi = &pcie->msi;
  710. unsigned long base;
  711. int err, i;
  712. mutex_init(&msi->lock);
  713. msi->chip.dev = dev;
  714. msi->chip.setup_irq = rcar_msi_setup_irq;
  715. msi->chip.setup_irqs = rcar_msi_setup_irqs;
  716. msi->chip.teardown_irq = rcar_msi_teardown_irq;
  717. msi->domain = irq_domain_add_linear(dev->of_node, INT_PCI_MSI_NR,
  718. &msi_domain_ops, &msi->chip);
  719. if (!msi->domain) {
  720. dev_err(dev, "failed to create IRQ domain\n");
  721. return -ENOMEM;
  722. }
  723. for (i = 0; i < INT_PCI_MSI_NR; i++)
  724. irq_create_mapping(msi->domain, i);
  725. /* Two irqs are for MSI, but they are also used for non-MSI irqs */
  726. err = devm_request_irq(dev, msi->irq1, rcar_pcie_msi_irq,
  727. IRQF_SHARED | IRQF_NO_THREAD,
  728. rcar_msi_irq_chip.name, pcie);
  729. if (err < 0) {
  730. dev_err(dev, "failed to request IRQ: %d\n", err);
  731. goto err;
  732. }
  733. err = devm_request_irq(dev, msi->irq2, rcar_pcie_msi_irq,
  734. IRQF_SHARED | IRQF_NO_THREAD,
  735. rcar_msi_irq_chip.name, pcie);
  736. if (err < 0) {
  737. dev_err(dev, "failed to request IRQ: %d\n", err);
  738. goto err;
  739. }
  740. /* setup MSI data target */
  741. msi->pages = __get_free_pages(GFP_KERNEL, 0);
  742. base = virt_to_phys((void *)msi->pages);
  743. rcar_pci_write_reg(pcie, base | MSIFE, PCIEMSIALR);
  744. rcar_pci_write_reg(pcie, 0, PCIEMSIAUR);
  745. /* enable all MSI interrupts */
  746. rcar_pci_write_reg(pcie, 0xffffffff, PCIEMSIIER);
  747. return 0;
  748. err:
  749. rcar_pcie_unmap_msi(pcie);
  750. return err;
  751. }
  752. static void rcar_pcie_teardown_msi(struct rcar_pcie *pcie)
  753. {
  754. struct rcar_msi *msi = &pcie->msi;
  755. /* Disable all MSI interrupts */
  756. rcar_pci_write_reg(pcie, 0, PCIEMSIIER);
  757. /* Disable address decoding of the MSI interrupt, MSIFE */
  758. rcar_pci_write_reg(pcie, 0, PCIEMSIALR);
  759. free_pages(msi->pages, 0);
  760. rcar_pcie_unmap_msi(pcie);
  761. }
  762. static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
  763. {
  764. struct device *dev = pcie->dev;
  765. struct resource res;
  766. int err, i;
  767. pcie->phy = devm_phy_optional_get(dev, "pcie");
  768. if (IS_ERR(pcie->phy))
  769. return PTR_ERR(pcie->phy);
  770. err = of_address_to_resource(dev->of_node, 0, &res);
  771. if (err)
  772. return err;
  773. pcie->base = devm_ioremap_resource(dev, &res);
  774. if (IS_ERR(pcie->base))
  775. return PTR_ERR(pcie->base);
  776. pcie->bus_clk = devm_clk_get(dev, "pcie_bus");
  777. if (IS_ERR(pcie->bus_clk)) {
  778. dev_err(dev, "cannot get pcie bus clock\n");
  779. return PTR_ERR(pcie->bus_clk);
  780. }
  781. i = irq_of_parse_and_map(dev->of_node, 0);
  782. if (!i) {
  783. dev_err(dev, "cannot get platform resources for msi interrupt\n");
  784. err = -ENOENT;
  785. goto err_irq1;
  786. }
  787. pcie->msi.irq1 = i;
  788. i = irq_of_parse_and_map(dev->of_node, 1);
  789. if (!i) {
  790. dev_err(dev, "cannot get platform resources for msi interrupt\n");
  791. err = -ENOENT;
  792. goto err_irq2;
  793. }
  794. pcie->msi.irq2 = i;
  795. return 0;
  796. err_irq2:
  797. irq_dispose_mapping(pcie->msi.irq1);
  798. err_irq1:
  799. return err;
  800. }
  801. static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
  802. struct of_pci_range *range,
  803. int *index)
  804. {
  805. u64 restype = range->flags;
  806. u64 cpu_addr = range->cpu_addr;
  807. u64 cpu_end = range->cpu_addr + range->size;
  808. u64 pci_addr = range->pci_addr;
  809. u32 flags = LAM_64BIT | LAR_ENABLE;
  810. u64 mask;
  811. u64 size;
  812. int idx = *index;
  813. if (restype & IORESOURCE_PREFETCH)
  814. flags |= LAM_PREFETCH;
  815. /*
  816. * If the size of the range is larger than the alignment of the start
  817. * address, we have to use multiple entries to perform the mapping.
  818. */
  819. if (cpu_addr > 0) {
  820. unsigned long nr_zeros = __ffs64(cpu_addr);
  821. u64 alignment = 1ULL << nr_zeros;
  822. size = min(range->size, alignment);
  823. } else {
  824. size = range->size;
  825. }
  826. /* Hardware supports max 4GiB inbound region */
  827. size = min(size, 1ULL << 32);
  828. mask = roundup_pow_of_two(size) - 1;
  829. mask &= ~0xf;
  830. while (cpu_addr < cpu_end) {
  831. /*
  832. * Set up 64-bit inbound regions as the range parser doesn't
  833. * distinguish between 32 and 64-bit types.
  834. */
  835. rcar_pci_write_reg(pcie, lower_32_bits(pci_addr),
  836. PCIEPRAR(idx));
  837. rcar_pci_write_reg(pcie, lower_32_bits(cpu_addr), PCIELAR(idx));
  838. rcar_pci_write_reg(pcie, lower_32_bits(mask) | flags,
  839. PCIELAMR(idx));
  840. rcar_pci_write_reg(pcie, upper_32_bits(pci_addr),
  841. PCIEPRAR(idx + 1));
  842. rcar_pci_write_reg(pcie, upper_32_bits(cpu_addr),
  843. PCIELAR(idx + 1));
  844. rcar_pci_write_reg(pcie, 0, PCIELAMR(idx + 1));
  845. pci_addr += size;
  846. cpu_addr += size;
  847. idx += 2;
  848. if (idx > MAX_NR_INBOUND_MAPS) {
  849. dev_err(pcie->dev, "Failed to map inbound regions!\n");
  850. return -EINVAL;
  851. }
  852. }
  853. *index = idx;
  854. return 0;
  855. }
  856. static int rcar_pcie_parse_map_dma_ranges(struct rcar_pcie *pcie,
  857. struct device_node *np)
  858. {
  859. struct of_pci_range range;
  860. struct of_pci_range_parser parser;
  861. int index = 0;
  862. int err;
  863. if (of_pci_dma_range_parser_init(&parser, np))
  864. return -EINVAL;
  865. /* Get the dma-ranges from DT */
  866. for_each_of_pci_range(&parser, &range) {
  867. u64 end = range.cpu_addr + range.size - 1;
  868. dev_dbg(pcie->dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",
  869. range.flags, range.cpu_addr, end, range.pci_addr);
  870. err = rcar_pcie_inbound_ranges(pcie, &range, &index);
  871. if (err)
  872. return err;
  873. }
  874. return 0;
  875. }
  876. static const struct of_device_id rcar_pcie_of_match[] = {
  877. { .compatible = "renesas,pcie-r8a7779",
  878. .data = rcar_pcie_phy_init_h1 },
  879. { .compatible = "renesas,pcie-r8a7790",
  880. .data = rcar_pcie_phy_init_gen2 },
  881. { .compatible = "renesas,pcie-r8a7791",
  882. .data = rcar_pcie_phy_init_gen2 },
  883. { .compatible = "renesas,pcie-rcar-gen2",
  884. .data = rcar_pcie_phy_init_gen2 },
  885. { .compatible = "renesas,pcie-r8a7795",
  886. .data = rcar_pcie_phy_init_gen3 },
  887. { .compatible = "renesas,pcie-rcar-gen3",
  888. .data = rcar_pcie_phy_init_gen3 },
  889. {},
  890. };
  891. static int rcar_pcie_probe(struct platform_device *pdev)
  892. {
  893. struct device *dev = &pdev->dev;
  894. struct rcar_pcie *pcie;
  895. unsigned int data;
  896. int err;
  897. int (*phy_init_fn)(struct rcar_pcie *);
  898. struct pci_host_bridge *bridge;
  899. bridge = pci_alloc_host_bridge(sizeof(*pcie));
  900. if (!bridge)
  901. return -ENOMEM;
  902. pcie = pci_host_bridge_priv(bridge);
  903. pcie->dev = dev;
  904. err = pci_parse_request_of_pci_ranges(dev, &pcie->resources, NULL);
  905. if (err)
  906. goto err_free_bridge;
  907. pm_runtime_enable(pcie->dev);
  908. err = pm_runtime_get_sync(pcie->dev);
  909. if (err < 0) {
  910. dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
  911. goto err_pm_disable;
  912. }
  913. err = rcar_pcie_get_resources(pcie);
  914. if (err < 0) {
  915. dev_err(dev, "failed to request resources: %d\n", err);
  916. goto err_pm_put;
  917. }
  918. err = clk_prepare_enable(pcie->bus_clk);
  919. if (err) {
  920. dev_err(dev, "failed to enable bus clock: %d\n", err);
  921. goto err_unmap_msi_irqs;
  922. }
  923. err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
  924. if (err)
  925. goto err_clk_disable;
  926. phy_init_fn = of_device_get_match_data(dev);
  927. err = phy_init_fn(pcie);
  928. if (err) {
  929. dev_err(dev, "failed to init PCIe PHY\n");
  930. goto err_clk_disable;
  931. }
  932. /* Failure to get a link might just be that no cards are inserted */
  933. if (rcar_pcie_hw_init(pcie)) {
  934. dev_info(dev, "PCIe link down\n");
  935. err = -ENODEV;
  936. goto err_clk_disable;
  937. }
  938. data = rcar_pci_read_reg(pcie, MACSR);
  939. dev_info(dev, "PCIe x%d: link up\n", (data >> 20) & 0x3f);
  940. if (IS_ENABLED(CONFIG_PCI_MSI)) {
  941. err = rcar_pcie_enable_msi(pcie);
  942. if (err < 0) {
  943. dev_err(dev,
  944. "failed to enable MSI support: %d\n",
  945. err);
  946. goto err_clk_disable;
  947. }
  948. }
  949. err = rcar_pcie_enable(pcie);
  950. if (err)
  951. goto err_msi_teardown;
  952. return 0;
  953. err_msi_teardown:
  954. if (IS_ENABLED(CONFIG_PCI_MSI))
  955. rcar_pcie_teardown_msi(pcie);
  956. err_clk_disable:
  957. clk_disable_unprepare(pcie->bus_clk);
  958. err_unmap_msi_irqs:
  959. irq_dispose_mapping(pcie->msi.irq2);
  960. irq_dispose_mapping(pcie->msi.irq1);
  961. err_pm_put:
  962. pm_runtime_put(dev);
  963. err_pm_disable:
  964. pm_runtime_disable(dev);
  965. pci_free_resource_list(&pcie->resources);
  966. err_free_bridge:
  967. pci_free_host_bridge(bridge);
  968. return err;
  969. }
  970. static struct platform_driver rcar_pcie_driver = {
  971. .driver = {
  972. .name = "rcar-pcie",
  973. .of_match_table = rcar_pcie_of_match,
  974. .suppress_bind_attrs = true,
  975. },
  976. .probe = rcar_pcie_probe,
  977. };
  978. builtin_platform_driver(rcar_pcie_driver);