pcie-artpec6.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * PCIe host controller driver for Axis ARTPEC-6 SoC
  4. *
  5. * Author: Niklas Cassel <niklas.cassel@axis.com>
  6. *
  7. * Based on work done by Phil Edworthy <phil@edworthys.org>
  8. */
  9. #include <linux/delay.h>
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/of_device.h>
  13. #include <linux/pci.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/resource.h>
  16. #include <linux/signal.h>
  17. #include <linux/types.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/mfd/syscon.h>
  20. #include <linux/regmap.h>
  21. #include "pcie-designware.h"
  22. #define to_artpec6_pcie(x) dev_get_drvdata((x)->dev)
  23. enum artpec_pcie_variants {
  24. ARTPEC6,
  25. ARTPEC7,
  26. };
  27. struct artpec6_pcie {
  28. struct dw_pcie *pci;
  29. struct regmap *regmap; /* DT axis,syscon-pcie */
  30. void __iomem *phy_base; /* DT phy */
  31. enum artpec_pcie_variants variant;
  32. enum dw_pcie_device_mode mode;
  33. };
  34. struct artpec_pcie_of_data {
  35. enum artpec_pcie_variants variant;
  36. enum dw_pcie_device_mode mode;
  37. };
  38. static const struct of_device_id artpec6_pcie_of_match[];
  39. /* PCIe Port Logic registers (memory-mapped) */
  40. #define PL_OFFSET 0x700
  41. #define ACK_F_ASPM_CTRL_OFF (PL_OFFSET + 0xc)
  42. #define ACK_N_FTS_MASK GENMASK(15, 8)
  43. #define ACK_N_FTS(x) (((x) << 8) & ACK_N_FTS_MASK)
  44. #define FAST_TRAINING_SEQ_MASK GENMASK(7, 0)
  45. #define FAST_TRAINING_SEQ(x) (((x) << 0) & FAST_TRAINING_SEQ_MASK)
  46. /* ARTPEC-6 specific registers */
  47. #define PCIECFG 0x18
  48. #define PCIECFG_DBG_OEN BIT(24)
  49. #define PCIECFG_CORE_RESET_REQ BIT(21)
  50. #define PCIECFG_LTSSM_ENABLE BIT(20)
  51. #define PCIECFG_DEVICE_TYPE_MASK GENMASK(19, 16)
  52. #define PCIECFG_CLKREQ_B BIT(11)
  53. #define PCIECFG_REFCLK_ENABLE BIT(10)
  54. #define PCIECFG_PLL_ENABLE BIT(9)
  55. #define PCIECFG_PCLK_ENABLE BIT(8)
  56. #define PCIECFG_RISRCREN BIT(4)
  57. #define PCIECFG_MODE_TX_DRV_EN BIT(3)
  58. #define PCIECFG_CISRREN BIT(2)
  59. #define PCIECFG_MACRO_ENABLE BIT(0)
  60. /* ARTPEC-7 specific fields */
  61. #define PCIECFG_REFCLKSEL BIT(23)
  62. #define PCIECFG_NOC_RESET BIT(3)
  63. #define PCIESTAT 0x1c
  64. /* ARTPEC-7 specific fields */
  65. #define PCIESTAT_EXTREFCLK BIT(3)
  66. #define NOCCFG 0x40
  67. #define NOCCFG_ENABLE_CLK_PCIE BIT(4)
  68. #define NOCCFG_POWER_PCIE_IDLEACK BIT(3)
  69. #define NOCCFG_POWER_PCIE_IDLE BIT(2)
  70. #define NOCCFG_POWER_PCIE_IDLEREQ BIT(1)
  71. #define PHY_STATUS 0x118
  72. #define PHY_COSPLLLOCK BIT(0)
  73. #define PHY_TX_ASIC_OUT 0x4040
  74. #define PHY_TX_ASIC_OUT_TX_ACK BIT(0)
  75. #define PHY_RX_ASIC_OUT 0x405c
  76. #define PHY_RX_ASIC_OUT_ACK BIT(0)
  77. static u32 artpec6_pcie_readl(struct artpec6_pcie *artpec6_pcie, u32 offset)
  78. {
  79. u32 val;
  80. regmap_read(artpec6_pcie->regmap, offset, &val);
  81. return val;
  82. }
  83. static void artpec6_pcie_writel(struct artpec6_pcie *artpec6_pcie, u32 offset, u32 val)
  84. {
  85. regmap_write(artpec6_pcie->regmap, offset, val);
  86. }
  87. static u64 artpec6_pcie_cpu_addr_fixup(struct dw_pcie *pci, u64 pci_addr)
  88. {
  89. struct artpec6_pcie *artpec6_pcie = to_artpec6_pcie(pci);
  90. struct pcie_port *pp = &pci->pp;
  91. struct dw_pcie_ep *ep = &pci->ep;
  92. switch (artpec6_pcie->mode) {
  93. case DW_PCIE_RC_TYPE:
  94. return pci_addr - pp->cfg0_base;
  95. case DW_PCIE_EP_TYPE:
  96. return pci_addr - ep->phys_base;
  97. default:
  98. dev_err(pci->dev, "UNKNOWN device type\n");
  99. }
  100. return pci_addr;
  101. }
  102. static int artpec6_pcie_establish_link(struct dw_pcie *pci)
  103. {
  104. struct artpec6_pcie *artpec6_pcie = to_artpec6_pcie(pci);
  105. u32 val;
  106. val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
  107. val |= PCIECFG_LTSSM_ENABLE;
  108. artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
  109. return 0;
  110. }
  111. static void artpec6_pcie_stop_link(struct dw_pcie *pci)
  112. {
  113. struct artpec6_pcie *artpec6_pcie = to_artpec6_pcie(pci);
  114. u32 val;
  115. val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
  116. val &= ~PCIECFG_LTSSM_ENABLE;
  117. artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
  118. }
  119. static const struct dw_pcie_ops dw_pcie_ops = {
  120. .cpu_addr_fixup = artpec6_pcie_cpu_addr_fixup,
  121. .start_link = artpec6_pcie_establish_link,
  122. .stop_link = artpec6_pcie_stop_link,
  123. };
  124. static void artpec6_pcie_wait_for_phy_a6(struct artpec6_pcie *artpec6_pcie)
  125. {
  126. struct dw_pcie *pci = artpec6_pcie->pci;
  127. struct device *dev = pci->dev;
  128. u32 val;
  129. unsigned int retries;
  130. retries = 50;
  131. do {
  132. usleep_range(1000, 2000);
  133. val = artpec6_pcie_readl(artpec6_pcie, NOCCFG);
  134. retries--;
  135. } while (retries &&
  136. (val & (NOCCFG_POWER_PCIE_IDLEACK | NOCCFG_POWER_PCIE_IDLE)));
  137. if (!retries)
  138. dev_err(dev, "PCIe clock manager did not leave idle state\n");
  139. retries = 50;
  140. do {
  141. usleep_range(1000, 2000);
  142. val = readl(artpec6_pcie->phy_base + PHY_STATUS);
  143. retries--;
  144. } while (retries && !(val & PHY_COSPLLLOCK));
  145. if (!retries)
  146. dev_err(dev, "PHY PLL did not lock\n");
  147. }
  148. static void artpec6_pcie_wait_for_phy_a7(struct artpec6_pcie *artpec6_pcie)
  149. {
  150. struct dw_pcie *pci = artpec6_pcie->pci;
  151. struct device *dev = pci->dev;
  152. u32 val;
  153. u16 phy_status_tx, phy_status_rx;
  154. unsigned int retries;
  155. retries = 50;
  156. do {
  157. usleep_range(1000, 2000);
  158. val = artpec6_pcie_readl(artpec6_pcie, NOCCFG);
  159. retries--;
  160. } while (retries &&
  161. (val & (NOCCFG_POWER_PCIE_IDLEACK | NOCCFG_POWER_PCIE_IDLE)));
  162. if (!retries)
  163. dev_err(dev, "PCIe clock manager did not leave idle state\n");
  164. retries = 50;
  165. do {
  166. usleep_range(1000, 2000);
  167. phy_status_tx = readw(artpec6_pcie->phy_base + PHY_TX_ASIC_OUT);
  168. phy_status_rx = readw(artpec6_pcie->phy_base + PHY_RX_ASIC_OUT);
  169. retries--;
  170. } while (retries && ((phy_status_tx & PHY_TX_ASIC_OUT_TX_ACK) ||
  171. (phy_status_rx & PHY_RX_ASIC_OUT_ACK)));
  172. if (!retries)
  173. dev_err(dev, "PHY did not enter Pn state\n");
  174. }
  175. static void artpec6_pcie_wait_for_phy(struct artpec6_pcie *artpec6_pcie)
  176. {
  177. switch (artpec6_pcie->variant) {
  178. case ARTPEC6:
  179. artpec6_pcie_wait_for_phy_a6(artpec6_pcie);
  180. break;
  181. case ARTPEC7:
  182. artpec6_pcie_wait_for_phy_a7(artpec6_pcie);
  183. break;
  184. }
  185. }
  186. static void artpec6_pcie_init_phy_a6(struct artpec6_pcie *artpec6_pcie)
  187. {
  188. u32 val;
  189. val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
  190. val |= PCIECFG_RISRCREN | /* Receiver term. 50 Ohm */
  191. PCIECFG_MODE_TX_DRV_EN |
  192. PCIECFG_CISRREN | /* Reference clock term. 100 Ohm */
  193. PCIECFG_MACRO_ENABLE;
  194. val |= PCIECFG_REFCLK_ENABLE;
  195. val &= ~PCIECFG_DBG_OEN;
  196. val &= ~PCIECFG_CLKREQ_B;
  197. artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
  198. usleep_range(5000, 6000);
  199. val = artpec6_pcie_readl(artpec6_pcie, NOCCFG);
  200. val |= NOCCFG_ENABLE_CLK_PCIE;
  201. artpec6_pcie_writel(artpec6_pcie, NOCCFG, val);
  202. usleep_range(20, 30);
  203. val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
  204. val |= PCIECFG_PCLK_ENABLE | PCIECFG_PLL_ENABLE;
  205. artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
  206. usleep_range(6000, 7000);
  207. val = artpec6_pcie_readl(artpec6_pcie, NOCCFG);
  208. val &= ~NOCCFG_POWER_PCIE_IDLEREQ;
  209. artpec6_pcie_writel(artpec6_pcie, NOCCFG, val);
  210. }
  211. static void artpec6_pcie_init_phy_a7(struct artpec6_pcie *artpec6_pcie)
  212. {
  213. struct dw_pcie *pci = artpec6_pcie->pci;
  214. u32 val;
  215. bool extrefclk;
  216. /* Check if external reference clock is connected */
  217. val = artpec6_pcie_readl(artpec6_pcie, PCIESTAT);
  218. extrefclk = !!(val & PCIESTAT_EXTREFCLK);
  219. dev_dbg(pci->dev, "Using reference clock: %s\n",
  220. extrefclk ? "external" : "internal");
  221. val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
  222. val |= PCIECFG_RISRCREN | /* Receiver term. 50 Ohm */
  223. PCIECFG_PCLK_ENABLE;
  224. if (extrefclk)
  225. val |= PCIECFG_REFCLKSEL;
  226. else
  227. val &= ~PCIECFG_REFCLKSEL;
  228. artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
  229. usleep_range(10, 20);
  230. val = artpec6_pcie_readl(artpec6_pcie, NOCCFG);
  231. val |= NOCCFG_ENABLE_CLK_PCIE;
  232. artpec6_pcie_writel(artpec6_pcie, NOCCFG, val);
  233. usleep_range(20, 30);
  234. val = artpec6_pcie_readl(artpec6_pcie, NOCCFG);
  235. val &= ~NOCCFG_POWER_PCIE_IDLEREQ;
  236. artpec6_pcie_writel(artpec6_pcie, NOCCFG, val);
  237. }
  238. static void artpec6_pcie_init_phy(struct artpec6_pcie *artpec6_pcie)
  239. {
  240. switch (artpec6_pcie->variant) {
  241. case ARTPEC6:
  242. artpec6_pcie_init_phy_a6(artpec6_pcie);
  243. break;
  244. case ARTPEC7:
  245. artpec6_pcie_init_phy_a7(artpec6_pcie);
  246. break;
  247. }
  248. }
  249. static void artpec6_pcie_set_nfts(struct artpec6_pcie *artpec6_pcie)
  250. {
  251. struct dw_pcie *pci = artpec6_pcie->pci;
  252. u32 val;
  253. if (artpec6_pcie->variant != ARTPEC7)
  254. return;
  255. /*
  256. * Increase the N_FTS (Number of Fast Training Sequences)
  257. * to be transmitted when transitioning from L0s to L0.
  258. */
  259. val = dw_pcie_readl_dbi(pci, ACK_F_ASPM_CTRL_OFF);
  260. val &= ~ACK_N_FTS_MASK;
  261. val |= ACK_N_FTS(180);
  262. dw_pcie_writel_dbi(pci, ACK_F_ASPM_CTRL_OFF, val);
  263. /*
  264. * Set the Number of Fast Training Sequences that the core
  265. * advertises as its N_FTS during Gen2 or Gen3 link training.
  266. */
  267. val = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
  268. val &= ~FAST_TRAINING_SEQ_MASK;
  269. val |= FAST_TRAINING_SEQ(180);
  270. dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, val);
  271. }
  272. static void artpec6_pcie_assert_core_reset(struct artpec6_pcie *artpec6_pcie)
  273. {
  274. u32 val;
  275. val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
  276. switch (artpec6_pcie->variant) {
  277. case ARTPEC6:
  278. val |= PCIECFG_CORE_RESET_REQ;
  279. break;
  280. case ARTPEC7:
  281. val &= ~PCIECFG_NOC_RESET;
  282. break;
  283. }
  284. artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
  285. }
  286. static void artpec6_pcie_deassert_core_reset(struct artpec6_pcie *artpec6_pcie)
  287. {
  288. u32 val;
  289. val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
  290. switch (artpec6_pcie->variant) {
  291. case ARTPEC6:
  292. val &= ~PCIECFG_CORE_RESET_REQ;
  293. break;
  294. case ARTPEC7:
  295. val |= PCIECFG_NOC_RESET;
  296. break;
  297. }
  298. artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
  299. usleep_range(100, 200);
  300. }
  301. static void artpec6_pcie_enable_interrupts(struct artpec6_pcie *artpec6_pcie)
  302. {
  303. struct dw_pcie *pci = artpec6_pcie->pci;
  304. struct pcie_port *pp = &pci->pp;
  305. if (IS_ENABLED(CONFIG_PCI_MSI))
  306. dw_pcie_msi_init(pp);
  307. }
  308. static int artpec6_pcie_host_init(struct pcie_port *pp)
  309. {
  310. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  311. struct artpec6_pcie *artpec6_pcie = to_artpec6_pcie(pci);
  312. artpec6_pcie_assert_core_reset(artpec6_pcie);
  313. artpec6_pcie_init_phy(artpec6_pcie);
  314. artpec6_pcie_deassert_core_reset(artpec6_pcie);
  315. artpec6_pcie_wait_for_phy(artpec6_pcie);
  316. artpec6_pcie_set_nfts(artpec6_pcie);
  317. dw_pcie_setup_rc(pp);
  318. artpec6_pcie_establish_link(pci);
  319. dw_pcie_wait_for_link(pci);
  320. artpec6_pcie_enable_interrupts(artpec6_pcie);
  321. return 0;
  322. }
  323. static const struct dw_pcie_host_ops artpec6_pcie_host_ops = {
  324. .host_init = artpec6_pcie_host_init,
  325. };
  326. static int artpec6_add_pcie_port(struct artpec6_pcie *artpec6_pcie,
  327. struct platform_device *pdev)
  328. {
  329. struct dw_pcie *pci = artpec6_pcie->pci;
  330. struct pcie_port *pp = &pci->pp;
  331. struct device *dev = pci->dev;
  332. int ret;
  333. if (IS_ENABLED(CONFIG_PCI_MSI)) {
  334. pp->msi_irq = platform_get_irq_byname(pdev, "msi");
  335. if (pp->msi_irq < 0) {
  336. dev_err(dev, "failed to get MSI irq\n");
  337. return pp->msi_irq;
  338. }
  339. }
  340. pp->ops = &artpec6_pcie_host_ops;
  341. ret = dw_pcie_host_init(pp);
  342. if (ret) {
  343. dev_err(dev, "failed to initialize host\n");
  344. return ret;
  345. }
  346. return 0;
  347. }
  348. static void artpec6_pcie_ep_init(struct dw_pcie_ep *ep)
  349. {
  350. struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
  351. struct artpec6_pcie *artpec6_pcie = to_artpec6_pcie(pci);
  352. enum pci_barno bar;
  353. artpec6_pcie_assert_core_reset(artpec6_pcie);
  354. artpec6_pcie_init_phy(artpec6_pcie);
  355. artpec6_pcie_deassert_core_reset(artpec6_pcie);
  356. artpec6_pcie_wait_for_phy(artpec6_pcie);
  357. artpec6_pcie_set_nfts(artpec6_pcie);
  358. for (bar = BAR_0; bar <= BAR_5; bar++)
  359. dw_pcie_ep_reset_bar(pci, bar);
  360. }
  361. static int artpec6_pcie_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
  362. enum pci_epc_irq_type type, u16 interrupt_num)
  363. {
  364. struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
  365. switch (type) {
  366. case PCI_EPC_IRQ_LEGACY:
  367. dev_err(pci->dev, "EP cannot trigger legacy IRQs\n");
  368. return -EINVAL;
  369. case PCI_EPC_IRQ_MSI:
  370. return dw_pcie_ep_raise_msi_irq(ep, func_no, interrupt_num);
  371. default:
  372. dev_err(pci->dev, "UNKNOWN IRQ type\n");
  373. }
  374. return 0;
  375. }
  376. static struct dw_pcie_ep_ops pcie_ep_ops = {
  377. .ep_init = artpec6_pcie_ep_init,
  378. .raise_irq = artpec6_pcie_raise_irq,
  379. };
  380. static int artpec6_add_pcie_ep(struct artpec6_pcie *artpec6_pcie,
  381. struct platform_device *pdev)
  382. {
  383. int ret;
  384. struct dw_pcie_ep *ep;
  385. struct resource *res;
  386. struct device *dev = &pdev->dev;
  387. struct dw_pcie *pci = artpec6_pcie->pci;
  388. ep = &pci->ep;
  389. ep->ops = &pcie_ep_ops;
  390. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi2");
  391. pci->dbi_base2 = devm_ioremap_resource(dev, res);
  392. if (IS_ERR(pci->dbi_base2))
  393. return PTR_ERR(pci->dbi_base2);
  394. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "addr_space");
  395. if (!res)
  396. return -EINVAL;
  397. ep->phys_base = res->start;
  398. ep->addr_size = resource_size(res);
  399. ret = dw_pcie_ep_init(ep);
  400. if (ret) {
  401. dev_err(dev, "failed to initialize endpoint\n");
  402. return ret;
  403. }
  404. return 0;
  405. }
  406. static int artpec6_pcie_probe(struct platform_device *pdev)
  407. {
  408. struct device *dev = &pdev->dev;
  409. struct dw_pcie *pci;
  410. struct artpec6_pcie *artpec6_pcie;
  411. struct resource *dbi_base;
  412. struct resource *phy_base;
  413. int ret;
  414. const struct of_device_id *match;
  415. const struct artpec_pcie_of_data *data;
  416. enum artpec_pcie_variants variant;
  417. enum dw_pcie_device_mode mode;
  418. match = of_match_device(artpec6_pcie_of_match, dev);
  419. if (!match)
  420. return -EINVAL;
  421. data = (struct artpec_pcie_of_data *)match->data;
  422. variant = (enum artpec_pcie_variants)data->variant;
  423. mode = (enum dw_pcie_device_mode)data->mode;
  424. artpec6_pcie = devm_kzalloc(dev, sizeof(*artpec6_pcie), GFP_KERNEL);
  425. if (!artpec6_pcie)
  426. return -ENOMEM;
  427. pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
  428. if (!pci)
  429. return -ENOMEM;
  430. pci->dev = dev;
  431. pci->ops = &dw_pcie_ops;
  432. artpec6_pcie->pci = pci;
  433. artpec6_pcie->variant = variant;
  434. artpec6_pcie->mode = mode;
  435. dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");
  436. pci->dbi_base = devm_ioremap_resource(dev, dbi_base);
  437. if (IS_ERR(pci->dbi_base))
  438. return PTR_ERR(pci->dbi_base);
  439. phy_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy");
  440. artpec6_pcie->phy_base = devm_ioremap_resource(dev, phy_base);
  441. if (IS_ERR(artpec6_pcie->phy_base))
  442. return PTR_ERR(artpec6_pcie->phy_base);
  443. artpec6_pcie->regmap =
  444. syscon_regmap_lookup_by_phandle(dev->of_node,
  445. "axis,syscon-pcie");
  446. if (IS_ERR(artpec6_pcie->regmap))
  447. return PTR_ERR(artpec6_pcie->regmap);
  448. platform_set_drvdata(pdev, artpec6_pcie);
  449. switch (artpec6_pcie->mode) {
  450. case DW_PCIE_RC_TYPE:
  451. if (!IS_ENABLED(CONFIG_PCIE_ARTPEC6_HOST))
  452. return -ENODEV;
  453. ret = artpec6_add_pcie_port(artpec6_pcie, pdev);
  454. if (ret < 0)
  455. return ret;
  456. break;
  457. case DW_PCIE_EP_TYPE: {
  458. u32 val;
  459. if (!IS_ENABLED(CONFIG_PCIE_ARTPEC6_EP))
  460. return -ENODEV;
  461. val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
  462. val &= ~PCIECFG_DEVICE_TYPE_MASK;
  463. artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
  464. ret = artpec6_add_pcie_ep(artpec6_pcie, pdev);
  465. if (ret < 0)
  466. return ret;
  467. break;
  468. }
  469. default:
  470. dev_err(dev, "INVALID device type %d\n", artpec6_pcie->mode);
  471. }
  472. return 0;
  473. }
  474. static const struct artpec_pcie_of_data artpec6_pcie_rc_of_data = {
  475. .variant = ARTPEC6,
  476. .mode = DW_PCIE_RC_TYPE,
  477. };
  478. static const struct artpec_pcie_of_data artpec6_pcie_ep_of_data = {
  479. .variant = ARTPEC6,
  480. .mode = DW_PCIE_EP_TYPE,
  481. };
  482. static const struct artpec_pcie_of_data artpec7_pcie_rc_of_data = {
  483. .variant = ARTPEC7,
  484. .mode = DW_PCIE_RC_TYPE,
  485. };
  486. static const struct artpec_pcie_of_data artpec7_pcie_ep_of_data = {
  487. .variant = ARTPEC7,
  488. .mode = DW_PCIE_EP_TYPE,
  489. };
  490. static const struct of_device_id artpec6_pcie_of_match[] = {
  491. {
  492. .compatible = "axis,artpec6-pcie",
  493. .data = &artpec6_pcie_rc_of_data,
  494. },
  495. {
  496. .compatible = "axis,artpec6-pcie-ep",
  497. .data = &artpec6_pcie_ep_of_data,
  498. },
  499. {
  500. .compatible = "axis,artpec7-pcie",
  501. .data = &artpec7_pcie_rc_of_data,
  502. },
  503. {
  504. .compatible = "axis,artpec7-pcie-ep",
  505. .data = &artpec7_pcie_ep_of_data,
  506. },
  507. {},
  508. };
  509. static struct platform_driver artpec6_pcie_driver = {
  510. .probe = artpec6_pcie_probe,
  511. .driver = {
  512. .name = "artpec6-pcie",
  513. .of_match_table = artpec6_pcie_of_match,
  514. .suppress_bind_attrs = true,
  515. },
  516. };
  517. builtin_platform_driver(artpec6_pcie_driver);