pcie-mobiveil-host.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * PCIe host controller driver for Mobiveil PCIe Host controller
  4. *
  5. * Copyright (c) 2018 Mobiveil Inc.
  6. * Copyright 2019-2020 NXP
  7. *
  8. * Author: Subrahmanya Lingappa <l.subrahmanya@mobiveil.co.in>
  9. * Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
  10. */
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/irq.h>
  14. #include <linux/irqchip/irq-msi-lib.h>
  15. #include <linux/irqchip/chained_irq.h>
  16. #include <linux/irqdomain.h>
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/msi.h>
  20. #include <linux/of_pci.h>
  21. #include <linux/pci.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/slab.h>
  24. #include "pcie-mobiveil.h"
  25. static bool mobiveil_pcie_valid_device(struct pci_bus *bus, unsigned int devfn)
  26. {
  27. /* Only one device down on each root port */
  28. if (pci_is_root_bus(bus) && (devfn > 0))
  29. return false;
  30. /*
  31. * Do not read more than one device on the bus directly
  32. * attached to RC
  33. */
  34. if ((bus->primary == to_pci_host_bridge(bus->bridge)->busnr) && (PCI_SLOT(devfn) > 0))
  35. return false;
  36. return true;
  37. }
  38. /*
  39. * mobiveil_pcie_map_bus - routine to get the configuration base of either
  40. * root port or endpoint
  41. */
  42. static void __iomem *mobiveil_pcie_map_bus(struct pci_bus *bus,
  43. unsigned int devfn, int where)
  44. {
  45. struct mobiveil_pcie *pcie = bus->sysdata;
  46. struct mobiveil_root_port *rp = &pcie->rp;
  47. u32 value;
  48. if (!mobiveil_pcie_valid_device(bus, devfn))
  49. return NULL;
  50. /* RC config access */
  51. if (pci_is_root_bus(bus))
  52. return pcie->csr_axi_slave_base + where;
  53. /*
  54. * EP config access (in Config/APIO space)
  55. * Program PEX Address base (31..16 bits) with appropriate value
  56. * (BDF) in PAB_AXI_AMAP_PEX_WIN_L0 Register.
  57. * Relies on pci_lock serialization
  58. */
  59. value = bus->number << PAB_BUS_SHIFT |
  60. PCI_SLOT(devfn) << PAB_DEVICE_SHIFT |
  61. PCI_FUNC(devfn) << PAB_FUNCTION_SHIFT;
  62. mobiveil_csr_writel(pcie, value, PAB_AXI_AMAP_PEX_WIN_L(WIN_NUM_0));
  63. return rp->config_axi_slave_base + where;
  64. }
  65. static struct pci_ops mobiveil_pcie_ops = {
  66. .map_bus = mobiveil_pcie_map_bus,
  67. .read = pci_generic_config_read,
  68. .write = pci_generic_config_write,
  69. };
  70. static void mobiveil_pcie_isr(struct irq_desc *desc)
  71. {
  72. struct irq_chip *chip = irq_desc_get_chip(desc);
  73. struct mobiveil_pcie *pcie = irq_desc_get_handler_data(desc);
  74. struct device *dev = &pcie->pdev->dev;
  75. struct mobiveil_root_port *rp = &pcie->rp;
  76. struct mobiveil_msi *msi = &rp->msi;
  77. u32 msi_data, msi_addr_lo, msi_addr_hi;
  78. u32 intr_status, msi_status;
  79. unsigned long shifted_status;
  80. u32 bit, val, mask;
  81. /*
  82. * The core provides a single interrupt for both INTx/MSI messages.
  83. * So we'll read both INTx and MSI status
  84. */
  85. chained_irq_enter(chip, desc);
  86. /* read INTx status */
  87. val = mobiveil_csr_readl(pcie, PAB_INTP_AMBA_MISC_STAT);
  88. mask = mobiveil_csr_readl(pcie, PAB_INTP_AMBA_MISC_ENB);
  89. intr_status = val & mask;
  90. /* Handle INTx */
  91. if (intr_status & PAB_INTP_INTX_MASK) {
  92. shifted_status = mobiveil_csr_readl(pcie,
  93. PAB_INTP_AMBA_MISC_STAT);
  94. shifted_status &= PAB_INTP_INTX_MASK;
  95. shifted_status >>= PAB_INTX_START;
  96. do {
  97. for_each_set_bit(bit, &shifted_status, PCI_NUM_INTX) {
  98. int ret;
  99. ret = generic_handle_domain_irq(rp->intx_domain,
  100. bit + 1);
  101. if (ret)
  102. dev_err_ratelimited(dev, "unexpected IRQ, INT%d\n",
  103. bit);
  104. /* clear interrupt handled */
  105. mobiveil_csr_writel(pcie,
  106. 1 << (PAB_INTX_START + bit),
  107. PAB_INTP_AMBA_MISC_STAT);
  108. }
  109. shifted_status = mobiveil_csr_readl(pcie,
  110. PAB_INTP_AMBA_MISC_STAT);
  111. shifted_status &= PAB_INTP_INTX_MASK;
  112. shifted_status >>= PAB_INTX_START;
  113. } while (shifted_status != 0);
  114. }
  115. /* read extra MSI status register */
  116. msi_status = readl_relaxed(pcie->apb_csr_base + MSI_STATUS_OFFSET);
  117. /* handle MSI interrupts */
  118. while (msi_status & 1) {
  119. msi_data = readl_relaxed(pcie->apb_csr_base + MSI_DATA_OFFSET);
  120. /*
  121. * MSI_STATUS_OFFSET register gets updated to zero
  122. * once we pop not only the MSI data but also address
  123. * from MSI hardware FIFO. So keeping these following
  124. * two dummy reads.
  125. */
  126. msi_addr_lo = readl_relaxed(pcie->apb_csr_base +
  127. MSI_ADDR_L_OFFSET);
  128. msi_addr_hi = readl_relaxed(pcie->apb_csr_base +
  129. MSI_ADDR_H_OFFSET);
  130. dev_dbg(dev, "MSI registers, data: %08x, addr: %08x:%08x\n",
  131. msi_data, msi_addr_hi, msi_addr_lo);
  132. generic_handle_domain_irq(msi->dev_domain, msi_data);
  133. msi_status = readl_relaxed(pcie->apb_csr_base +
  134. MSI_STATUS_OFFSET);
  135. }
  136. /* Clear the interrupt status */
  137. mobiveil_csr_writel(pcie, intr_status, PAB_INTP_AMBA_MISC_STAT);
  138. chained_irq_exit(chip, desc);
  139. }
  140. static int mobiveil_pcie_parse_dt(struct mobiveil_pcie *pcie)
  141. {
  142. struct device *dev = &pcie->pdev->dev;
  143. struct platform_device *pdev = pcie->pdev;
  144. struct device_node *node = dev->of_node;
  145. struct mobiveil_root_port *rp = &pcie->rp;
  146. struct resource *res;
  147. /* map config resource */
  148. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  149. "config_axi_slave");
  150. rp->config_axi_slave_base = devm_pci_remap_cfg_resource(dev, res);
  151. if (IS_ERR(rp->config_axi_slave_base))
  152. return PTR_ERR(rp->config_axi_slave_base);
  153. rp->ob_io_res = res;
  154. /* map csr resource */
  155. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  156. "csr_axi_slave");
  157. pcie->csr_axi_slave_base = devm_pci_remap_cfg_resource(dev, res);
  158. if (IS_ERR(pcie->csr_axi_slave_base))
  159. return PTR_ERR(pcie->csr_axi_slave_base);
  160. pcie->pcie_reg_base = res->start;
  161. /* read the number of windows requested */
  162. if (of_property_read_u32(node, "apio-wins", &pcie->apio_wins))
  163. pcie->apio_wins = MAX_PIO_WINDOWS;
  164. if (of_property_read_u32(node, "ppio-wins", &pcie->ppio_wins))
  165. pcie->ppio_wins = MAX_PIO_WINDOWS;
  166. return 0;
  167. }
  168. static void mobiveil_pcie_enable_msi(struct mobiveil_pcie *pcie)
  169. {
  170. phys_addr_t msg_addr = pcie->pcie_reg_base;
  171. struct mobiveil_msi *msi = &pcie->rp.msi;
  172. msi->num_of_vectors = PCI_NUM_MSI;
  173. msi->msi_pages_phys = (phys_addr_t)msg_addr;
  174. writel_relaxed(lower_32_bits(msg_addr),
  175. pcie->apb_csr_base + MSI_BASE_LO_OFFSET);
  176. writel_relaxed(upper_32_bits(msg_addr),
  177. pcie->apb_csr_base + MSI_BASE_HI_OFFSET);
  178. writel_relaxed(4096, pcie->apb_csr_base + MSI_SIZE_OFFSET);
  179. writel_relaxed(1, pcie->apb_csr_base + MSI_ENABLE_OFFSET);
  180. }
  181. int mobiveil_host_init(struct mobiveil_pcie *pcie, bool reinit)
  182. {
  183. struct mobiveil_root_port *rp = &pcie->rp;
  184. struct pci_host_bridge *bridge = rp->bridge;
  185. u32 value, pab_ctrl, type;
  186. struct resource_entry *win;
  187. pcie->ib_wins_configured = 0;
  188. pcie->ob_wins_configured = 0;
  189. if (!reinit) {
  190. /* setup bus numbers */
  191. value = mobiveil_csr_readl(pcie, PCI_PRIMARY_BUS);
  192. value &= 0xff000000;
  193. value |= 0x00ff0100;
  194. mobiveil_csr_writel(pcie, value, PCI_PRIMARY_BUS);
  195. }
  196. /*
  197. * program Bus Master Enable Bit in Command Register in PAB Config
  198. * Space
  199. */
  200. value = mobiveil_csr_readl(pcie, PCI_COMMAND);
  201. value |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
  202. mobiveil_csr_writel(pcie, value, PCI_COMMAND);
  203. /*
  204. * program PIO Enable Bit to 1 (and PEX PIO Enable to 1) in PAB_CTRL
  205. * register
  206. */
  207. pab_ctrl = mobiveil_csr_readl(pcie, PAB_CTRL);
  208. pab_ctrl |= (1 << AMBA_PIO_ENABLE_SHIFT) | (1 << PEX_PIO_ENABLE_SHIFT);
  209. mobiveil_csr_writel(pcie, pab_ctrl, PAB_CTRL);
  210. /*
  211. * program PIO Enable Bit to 1 and Config Window Enable Bit to 1 in
  212. * PAB_AXI_PIO_CTRL Register
  213. */
  214. value = mobiveil_csr_readl(pcie, PAB_AXI_PIO_CTRL);
  215. value |= APIO_EN_MASK;
  216. mobiveil_csr_writel(pcie, value, PAB_AXI_PIO_CTRL);
  217. /* Enable PCIe PIO master */
  218. value = mobiveil_csr_readl(pcie, PAB_PEX_PIO_CTRL);
  219. value |= 1 << PIO_ENABLE_SHIFT;
  220. mobiveil_csr_writel(pcie, value, PAB_PEX_PIO_CTRL);
  221. /*
  222. * we'll program one outbound window for config reads and
  223. * another default inbound window for all the upstream traffic
  224. * rest of the outbound windows will be configured according to
  225. * the "ranges" field defined in device tree
  226. */
  227. /* config outbound translation window */
  228. program_ob_windows(pcie, WIN_NUM_0, rp->ob_io_res->start, 0,
  229. CFG_WINDOW_TYPE, resource_size(rp->ob_io_res));
  230. /* memory inbound translation window */
  231. program_ib_windows(pcie, WIN_NUM_0, 0, 0, MEM_WINDOW_TYPE, IB_WIN_SIZE);
  232. /* Get the I/O and memory ranges from DT */
  233. resource_list_for_each_entry(win, &bridge->windows) {
  234. if (resource_type(win->res) == IORESOURCE_MEM)
  235. type = MEM_WINDOW_TYPE;
  236. else if (resource_type(win->res) == IORESOURCE_IO)
  237. type = IO_WINDOW_TYPE;
  238. else
  239. continue;
  240. /* configure outbound translation window */
  241. program_ob_windows(pcie, pcie->ob_wins_configured,
  242. win->res->start,
  243. win->res->start - win->offset,
  244. type, resource_size(win->res));
  245. }
  246. /* fixup for PCIe class register */
  247. value = mobiveil_csr_readl(pcie, PAB_INTP_AXI_PIO_CLASS);
  248. value &= 0xff;
  249. value |= PCI_CLASS_BRIDGE_PCI_NORMAL << 8;
  250. mobiveil_csr_writel(pcie, value, PAB_INTP_AXI_PIO_CLASS);
  251. return 0;
  252. }
  253. static void mobiveil_mask_intx_irq(struct irq_data *data)
  254. {
  255. struct mobiveil_pcie *pcie = irq_data_get_irq_chip_data(data);
  256. struct mobiveil_root_port *rp;
  257. unsigned long flags;
  258. u32 mask, shifted_val;
  259. rp = &pcie->rp;
  260. mask = 1 << ((data->hwirq + PAB_INTX_START) - 1);
  261. raw_spin_lock_irqsave(&rp->intx_mask_lock, flags);
  262. shifted_val = mobiveil_csr_readl(pcie, PAB_INTP_AMBA_MISC_ENB);
  263. shifted_val &= ~mask;
  264. mobiveil_csr_writel(pcie, shifted_val, PAB_INTP_AMBA_MISC_ENB);
  265. raw_spin_unlock_irqrestore(&rp->intx_mask_lock, flags);
  266. }
  267. static void mobiveil_unmask_intx_irq(struct irq_data *data)
  268. {
  269. struct mobiveil_pcie *pcie = irq_data_get_irq_chip_data(data);
  270. struct mobiveil_root_port *rp;
  271. unsigned long flags;
  272. u32 shifted_val, mask;
  273. rp = &pcie->rp;
  274. mask = 1 << ((data->hwirq + PAB_INTX_START) - 1);
  275. raw_spin_lock_irqsave(&rp->intx_mask_lock, flags);
  276. shifted_val = mobiveil_csr_readl(pcie, PAB_INTP_AMBA_MISC_ENB);
  277. shifted_val |= mask;
  278. mobiveil_csr_writel(pcie, shifted_val, PAB_INTP_AMBA_MISC_ENB);
  279. raw_spin_unlock_irqrestore(&rp->intx_mask_lock, flags);
  280. }
  281. static struct irq_chip intx_irq_chip = {
  282. .name = "mobiveil_pcie:intx",
  283. .irq_enable = mobiveil_unmask_intx_irq,
  284. .irq_disable = mobiveil_mask_intx_irq,
  285. .irq_mask = mobiveil_mask_intx_irq,
  286. .irq_unmask = mobiveil_unmask_intx_irq,
  287. };
  288. /* routine to setup the INTx related data */
  289. static int mobiveil_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
  290. irq_hw_number_t hwirq)
  291. {
  292. irq_set_chip_and_handler(irq, &intx_irq_chip, handle_level_irq);
  293. irq_set_chip_data(irq, domain->host_data);
  294. return 0;
  295. }
  296. /* INTx domain operations structure */
  297. static const struct irq_domain_ops intx_domain_ops = {
  298. .map = mobiveil_pcie_intx_map,
  299. };
  300. #define MOBIVEIL_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS | \
  301. MSI_FLAG_USE_DEF_CHIP_OPS | \
  302. MSI_FLAG_NO_AFFINITY)
  303. #define MOBIVEIL_MSI_FLAGS_SUPPORTED (MSI_GENERIC_FLAGS_MASK | \
  304. MSI_FLAG_PCI_MSIX)
  305. static const struct msi_parent_ops mobiveil_msi_parent_ops = {
  306. .required_flags = MOBIVEIL_MSI_FLAGS_REQUIRED,
  307. .supported_flags = MOBIVEIL_MSI_FLAGS_SUPPORTED,
  308. .bus_select_token = DOMAIN_BUS_PCI_MSI,
  309. .prefix = "Mobiveil-",
  310. .init_dev_msi_info = msi_lib_init_dev_msi_info,
  311. };
  312. static void mobiveil_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
  313. {
  314. struct mobiveil_pcie *pcie = irq_data_get_irq_chip_data(data);
  315. phys_addr_t addr = pcie->pcie_reg_base + (data->hwirq * sizeof(int));
  316. msg->address_lo = lower_32_bits(addr);
  317. msg->address_hi = upper_32_bits(addr);
  318. msg->data = data->hwirq;
  319. dev_dbg(&pcie->pdev->dev, "msi#%d address_hi %#x address_lo %#x\n",
  320. (int)data->hwirq, msg->address_hi, msg->address_lo);
  321. }
  322. static struct irq_chip mobiveil_msi_bottom_irq_chip = {
  323. .name = "Mobiveil MSI",
  324. .irq_compose_msi_msg = mobiveil_compose_msi_msg,
  325. };
  326. static int mobiveil_irq_msi_domain_alloc(struct irq_domain *domain,
  327. unsigned int virq,
  328. unsigned int nr_irqs, void *args)
  329. {
  330. struct mobiveil_pcie *pcie = domain->host_data;
  331. struct mobiveil_msi *msi = &pcie->rp.msi;
  332. unsigned long bit;
  333. WARN_ON(nr_irqs != 1);
  334. mutex_lock(&msi->lock);
  335. bit = find_first_zero_bit(msi->msi_irq_in_use, msi->num_of_vectors);
  336. if (bit >= msi->num_of_vectors) {
  337. mutex_unlock(&msi->lock);
  338. return -ENOSPC;
  339. }
  340. set_bit(bit, msi->msi_irq_in_use);
  341. mutex_unlock(&msi->lock);
  342. irq_domain_set_info(domain, virq, bit, &mobiveil_msi_bottom_irq_chip,
  343. domain->host_data, handle_level_irq, NULL, NULL);
  344. return 0;
  345. }
  346. static void mobiveil_irq_msi_domain_free(struct irq_domain *domain,
  347. unsigned int virq,
  348. unsigned int nr_irqs)
  349. {
  350. struct irq_data *d = irq_domain_get_irq_data(domain, virq);
  351. struct mobiveil_pcie *pcie = irq_data_get_irq_chip_data(d);
  352. struct mobiveil_msi *msi = &pcie->rp.msi;
  353. mutex_lock(&msi->lock);
  354. if (!test_bit(d->hwirq, msi->msi_irq_in_use))
  355. dev_err(&pcie->pdev->dev, "trying to free unused MSI#%lu\n",
  356. d->hwirq);
  357. else
  358. __clear_bit(d->hwirq, msi->msi_irq_in_use);
  359. mutex_unlock(&msi->lock);
  360. }
  361. static const struct irq_domain_ops msi_domain_ops = {
  362. .alloc = mobiveil_irq_msi_domain_alloc,
  363. .free = mobiveil_irq_msi_domain_free,
  364. };
  365. static int mobiveil_allocate_msi_domains(struct mobiveil_pcie *pcie)
  366. {
  367. struct device *dev = &pcie->pdev->dev;
  368. struct mobiveil_msi *msi = &pcie->rp.msi;
  369. mutex_init(&msi->lock);
  370. struct irq_domain_info info = {
  371. .fwnode = dev_fwnode(dev),
  372. .ops = &msi_domain_ops,
  373. .host_data = pcie,
  374. .size = msi->num_of_vectors,
  375. };
  376. msi->dev_domain = msi_create_parent_irq_domain(&info, &mobiveil_msi_parent_ops);
  377. if (!msi->dev_domain) {
  378. dev_err(dev, "failed to create MSI domain\n");
  379. return -ENOMEM;
  380. }
  381. return 0;
  382. }
  383. static int mobiveil_pcie_init_irq_domain(struct mobiveil_pcie *pcie)
  384. {
  385. struct device *dev = &pcie->pdev->dev;
  386. struct mobiveil_root_port *rp = &pcie->rp;
  387. /* setup INTx */
  388. rp->intx_domain = irq_domain_create_linear(dev_fwnode(dev), PCI_NUM_INTX, &intx_domain_ops,
  389. pcie);
  390. if (!rp->intx_domain) {
  391. dev_err(dev, "Failed to get a INTx IRQ domain\n");
  392. return -ENOMEM;
  393. }
  394. raw_spin_lock_init(&rp->intx_mask_lock);
  395. /* setup MSI */
  396. return mobiveil_allocate_msi_domains(pcie);
  397. }
  398. static int mobiveil_pcie_integrated_interrupt_init(struct mobiveil_pcie *pcie)
  399. {
  400. struct platform_device *pdev = pcie->pdev;
  401. struct device *dev = &pdev->dev;
  402. struct mobiveil_root_port *rp = &pcie->rp;
  403. struct resource *res;
  404. int ret;
  405. /* map MSI config resource */
  406. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "apb_csr");
  407. pcie->apb_csr_base = devm_pci_remap_cfg_resource(dev, res);
  408. if (IS_ERR(pcie->apb_csr_base))
  409. return PTR_ERR(pcie->apb_csr_base);
  410. /* setup MSI hardware registers */
  411. mobiveil_pcie_enable_msi(pcie);
  412. rp->irq = platform_get_irq(pdev, 0);
  413. if (rp->irq < 0)
  414. return rp->irq;
  415. /* initialize the IRQ domains */
  416. ret = mobiveil_pcie_init_irq_domain(pcie);
  417. if (ret) {
  418. dev_err(dev, "Failed creating IRQ Domain\n");
  419. return ret;
  420. }
  421. irq_set_chained_handler_and_data(rp->irq, mobiveil_pcie_isr, pcie);
  422. /* Enable interrupts */
  423. mobiveil_csr_writel(pcie, (PAB_INTP_INTX_MASK | PAB_INTP_MSI_MASK),
  424. PAB_INTP_AMBA_MISC_ENB);
  425. return 0;
  426. }
  427. static int mobiveil_pcie_interrupt_init(struct mobiveil_pcie *pcie)
  428. {
  429. struct mobiveil_root_port *rp = &pcie->rp;
  430. if (rp->ops->interrupt_init)
  431. return rp->ops->interrupt_init(pcie);
  432. return mobiveil_pcie_integrated_interrupt_init(pcie);
  433. }
  434. static bool mobiveil_pcie_is_bridge(struct mobiveil_pcie *pcie)
  435. {
  436. u32 header_type;
  437. header_type = mobiveil_csr_readb(pcie, PCI_HEADER_TYPE);
  438. header_type &= PCI_HEADER_TYPE_MASK;
  439. return header_type == PCI_HEADER_TYPE_BRIDGE;
  440. }
  441. int mobiveil_pcie_host_probe(struct mobiveil_pcie *pcie)
  442. {
  443. struct mobiveil_root_port *rp = &pcie->rp;
  444. struct pci_host_bridge *bridge = rp->bridge;
  445. struct device *dev = &pcie->pdev->dev;
  446. int ret;
  447. ret = mobiveil_pcie_parse_dt(pcie);
  448. if (ret) {
  449. dev_err(dev, "Parsing DT failed, ret: %x\n", ret);
  450. return ret;
  451. }
  452. if (!mobiveil_pcie_is_bridge(pcie))
  453. return -ENODEV;
  454. /*
  455. * configure all inbound and outbound windows and prepare the RC for
  456. * config access
  457. */
  458. ret = mobiveil_host_init(pcie, false);
  459. if (ret) {
  460. dev_err(dev, "Failed to initialize host\n");
  461. return ret;
  462. }
  463. ret = mobiveil_pcie_interrupt_init(pcie);
  464. if (ret) {
  465. dev_err(dev, "Interrupt init failed\n");
  466. return ret;
  467. }
  468. /* Initialize bridge */
  469. bridge->sysdata = pcie;
  470. bridge->ops = &mobiveil_pcie_ops;
  471. ret = mobiveil_bringup_link(pcie);
  472. if (ret) {
  473. dev_info(dev, "link bring-up failed\n");
  474. return ret;
  475. }
  476. return pci_host_probe(bridge);
  477. }