pci-imx6.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. * PCIe host controller driver for Freescale i.MX6 SoCs
  3. *
  4. * Copyright (C) 2013 Kosagi
  5. * http://www.kosagi.com
  6. *
  7. * Author: Sean Cross <xobs@kosagi.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/delay.h>
  15. #include <linux/gpio.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mfd/syscon.h>
  18. #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
  19. #include <linux/module.h>
  20. #include <linux/of_gpio.h>
  21. #include <linux/pci.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/regmap.h>
  24. #include <linux/resource.h>
  25. #include <linux/signal.h>
  26. #include <linux/types.h>
  27. #include <linux/interrupt.h>
  28. #include "pcie-designware.h"
  29. #define to_imx6_pcie(x) container_of(x, struct imx6_pcie, pp)
  30. struct imx6_pcie {
  31. struct gpio_desc *reset_gpio;
  32. struct clk *pcie_bus;
  33. struct clk *pcie_phy;
  34. struct clk *pcie;
  35. struct pcie_port pp;
  36. struct regmap *iomuxc_gpr;
  37. void __iomem *mem_base;
  38. u32 tx_deemph_gen1;
  39. u32 tx_deemph_gen2_3p5db;
  40. u32 tx_deemph_gen2_6db;
  41. u32 tx_swing_full;
  42. u32 tx_swing_low;
  43. };
  44. /* PCIe Root Complex registers (memory-mapped) */
  45. #define PCIE_RC_LCR 0x7c
  46. #define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1 0x1
  47. #define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2 0x2
  48. #define PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK 0xf
  49. #define PCIE_RC_LCSR 0x80
  50. /* PCIe Port Logic registers (memory-mapped) */
  51. #define PL_OFFSET 0x700
  52. #define PCIE_PL_PFLR (PL_OFFSET + 0x08)
  53. #define PCIE_PL_PFLR_LINK_STATE_MASK (0x3f << 16)
  54. #define PCIE_PL_PFLR_FORCE_LINK (1 << 15)
  55. #define PCIE_PHY_DEBUG_R0 (PL_OFFSET + 0x28)
  56. #define PCIE_PHY_DEBUG_R1 (PL_OFFSET + 0x2c)
  57. #define PCIE_PHY_DEBUG_R1_XMLH_LINK_IN_TRAINING (1 << 29)
  58. #define PCIE_PHY_DEBUG_R1_XMLH_LINK_UP (1 << 4)
  59. #define PCIE_PHY_CTRL (PL_OFFSET + 0x114)
  60. #define PCIE_PHY_CTRL_DATA_LOC 0
  61. #define PCIE_PHY_CTRL_CAP_ADR_LOC 16
  62. #define PCIE_PHY_CTRL_CAP_DAT_LOC 17
  63. #define PCIE_PHY_CTRL_WR_LOC 18
  64. #define PCIE_PHY_CTRL_RD_LOC 19
  65. #define PCIE_PHY_STAT (PL_OFFSET + 0x110)
  66. #define PCIE_PHY_STAT_ACK_LOC 16
  67. #define PCIE_LINK_WIDTH_SPEED_CONTROL 0x80C
  68. #define PORT_LOGIC_SPEED_CHANGE (0x1 << 17)
  69. /* PHY registers (not memory-mapped) */
  70. #define PCIE_PHY_RX_ASIC_OUT 0x100D
  71. #define PCIE_PHY_RX_ASIC_OUT_VALID (1 << 0)
  72. #define PHY_RX_OVRD_IN_LO 0x1005
  73. #define PHY_RX_OVRD_IN_LO_RX_DATA_EN (1 << 5)
  74. #define PHY_RX_OVRD_IN_LO_RX_PLL_EN (1 << 3)
  75. static int pcie_phy_poll_ack(void __iomem *dbi_base, int exp_val)
  76. {
  77. u32 val;
  78. u32 max_iterations = 10;
  79. u32 wait_counter = 0;
  80. do {
  81. val = readl(dbi_base + PCIE_PHY_STAT);
  82. val = (val >> PCIE_PHY_STAT_ACK_LOC) & 0x1;
  83. wait_counter++;
  84. if (val == exp_val)
  85. return 0;
  86. udelay(1);
  87. } while (wait_counter < max_iterations);
  88. return -ETIMEDOUT;
  89. }
  90. static int pcie_phy_wait_ack(void __iomem *dbi_base, int addr)
  91. {
  92. u32 val;
  93. int ret;
  94. val = addr << PCIE_PHY_CTRL_DATA_LOC;
  95. writel(val, dbi_base + PCIE_PHY_CTRL);
  96. val |= (0x1 << PCIE_PHY_CTRL_CAP_ADR_LOC);
  97. writel(val, dbi_base + PCIE_PHY_CTRL);
  98. ret = pcie_phy_poll_ack(dbi_base, 1);
  99. if (ret)
  100. return ret;
  101. val = addr << PCIE_PHY_CTRL_DATA_LOC;
  102. writel(val, dbi_base + PCIE_PHY_CTRL);
  103. return pcie_phy_poll_ack(dbi_base, 0);
  104. }
  105. /* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */
  106. static int pcie_phy_read(void __iomem *dbi_base, int addr, int *data)
  107. {
  108. u32 val, phy_ctl;
  109. int ret;
  110. ret = pcie_phy_wait_ack(dbi_base, addr);
  111. if (ret)
  112. return ret;
  113. /* assert Read signal */
  114. phy_ctl = 0x1 << PCIE_PHY_CTRL_RD_LOC;
  115. writel(phy_ctl, dbi_base + PCIE_PHY_CTRL);
  116. ret = pcie_phy_poll_ack(dbi_base, 1);
  117. if (ret)
  118. return ret;
  119. val = readl(dbi_base + PCIE_PHY_STAT);
  120. *data = val & 0xffff;
  121. /* deassert Read signal */
  122. writel(0x00, dbi_base + PCIE_PHY_CTRL);
  123. return pcie_phy_poll_ack(dbi_base, 0);
  124. }
  125. static int pcie_phy_write(void __iomem *dbi_base, int addr, int data)
  126. {
  127. u32 var;
  128. int ret;
  129. /* write addr */
  130. /* cap addr */
  131. ret = pcie_phy_wait_ack(dbi_base, addr);
  132. if (ret)
  133. return ret;
  134. var = data << PCIE_PHY_CTRL_DATA_LOC;
  135. writel(var, dbi_base + PCIE_PHY_CTRL);
  136. /* capture data */
  137. var |= (0x1 << PCIE_PHY_CTRL_CAP_DAT_LOC);
  138. writel(var, dbi_base + PCIE_PHY_CTRL);
  139. ret = pcie_phy_poll_ack(dbi_base, 1);
  140. if (ret)
  141. return ret;
  142. /* deassert cap data */
  143. var = data << PCIE_PHY_CTRL_DATA_LOC;
  144. writel(var, dbi_base + PCIE_PHY_CTRL);
  145. /* wait for ack de-assertion */
  146. ret = pcie_phy_poll_ack(dbi_base, 0);
  147. if (ret)
  148. return ret;
  149. /* assert wr signal */
  150. var = 0x1 << PCIE_PHY_CTRL_WR_LOC;
  151. writel(var, dbi_base + PCIE_PHY_CTRL);
  152. /* wait for ack */
  153. ret = pcie_phy_poll_ack(dbi_base, 1);
  154. if (ret)
  155. return ret;
  156. /* deassert wr signal */
  157. var = data << PCIE_PHY_CTRL_DATA_LOC;
  158. writel(var, dbi_base + PCIE_PHY_CTRL);
  159. /* wait for ack de-assertion */
  160. ret = pcie_phy_poll_ack(dbi_base, 0);
  161. if (ret)
  162. return ret;
  163. writel(0x0, dbi_base + PCIE_PHY_CTRL);
  164. return 0;
  165. }
  166. static void imx6_pcie_reset_phy(struct pcie_port *pp)
  167. {
  168. u32 tmp;
  169. pcie_phy_read(pp->dbi_base, PHY_RX_OVRD_IN_LO, &tmp);
  170. tmp |= (PHY_RX_OVRD_IN_LO_RX_DATA_EN |
  171. PHY_RX_OVRD_IN_LO_RX_PLL_EN);
  172. pcie_phy_write(pp->dbi_base, PHY_RX_OVRD_IN_LO, tmp);
  173. usleep_range(2000, 3000);
  174. pcie_phy_read(pp->dbi_base, PHY_RX_OVRD_IN_LO, &tmp);
  175. tmp &= ~(PHY_RX_OVRD_IN_LO_RX_DATA_EN |
  176. PHY_RX_OVRD_IN_LO_RX_PLL_EN);
  177. pcie_phy_write(pp->dbi_base, PHY_RX_OVRD_IN_LO, tmp);
  178. }
  179. /* Added for PCI abort handling */
  180. static int imx6q_pcie_abort_handler(unsigned long addr,
  181. unsigned int fsr, struct pt_regs *regs)
  182. {
  183. return 0;
  184. }
  185. static int imx6_pcie_assert_core_reset(struct pcie_port *pp)
  186. {
  187. struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
  188. u32 val, gpr1, gpr12;
  189. /*
  190. * If the bootloader already enabled the link we need some special
  191. * handling to get the core back into a state where it is safe to
  192. * touch it for configuration. As there is no dedicated reset signal
  193. * wired up for MX6QDL, we need to manually force LTSSM into "detect"
  194. * state before completely disabling LTSSM, which is a prerequisite
  195. * for core configuration.
  196. *
  197. * If both LTSSM_ENABLE and REF_SSP_ENABLE are active we have a strong
  198. * indication that the bootloader activated the link.
  199. */
  200. regmap_read(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, &gpr1);
  201. regmap_read(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, &gpr12);
  202. if ((gpr1 & IMX6Q_GPR1_PCIE_REF_CLK_EN) &&
  203. (gpr12 & IMX6Q_GPR12_PCIE_CTL_2)) {
  204. val = readl(pp->dbi_base + PCIE_PL_PFLR);
  205. val &= ~PCIE_PL_PFLR_LINK_STATE_MASK;
  206. val |= PCIE_PL_PFLR_FORCE_LINK;
  207. writel(val, pp->dbi_base + PCIE_PL_PFLR);
  208. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
  209. IMX6Q_GPR12_PCIE_CTL_2, 0 << 10);
  210. }
  211. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
  212. IMX6Q_GPR1_PCIE_TEST_PD, 1 << 18);
  213. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
  214. IMX6Q_GPR1_PCIE_REF_CLK_EN, 0 << 16);
  215. return 0;
  216. }
  217. static int imx6_pcie_deassert_core_reset(struct pcie_port *pp)
  218. {
  219. struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
  220. int ret;
  221. ret = clk_prepare_enable(imx6_pcie->pcie_phy);
  222. if (ret) {
  223. dev_err(pp->dev, "unable to enable pcie_phy clock\n");
  224. goto err_pcie_phy;
  225. }
  226. ret = clk_prepare_enable(imx6_pcie->pcie_bus);
  227. if (ret) {
  228. dev_err(pp->dev, "unable to enable pcie_bus clock\n");
  229. goto err_pcie_bus;
  230. }
  231. ret = clk_prepare_enable(imx6_pcie->pcie);
  232. if (ret) {
  233. dev_err(pp->dev, "unable to enable pcie clock\n");
  234. goto err_pcie;
  235. }
  236. /* power up core phy and enable ref clock */
  237. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
  238. IMX6Q_GPR1_PCIE_TEST_PD, 0 << 18);
  239. /*
  240. * the async reset input need ref clock to sync internally,
  241. * when the ref clock comes after reset, internal synced
  242. * reset time is too short, cannot meet the requirement.
  243. * add one ~10us delay here.
  244. */
  245. udelay(10);
  246. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
  247. IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16);
  248. /* allow the clocks to stabilize */
  249. usleep_range(200, 500);
  250. /* Some boards don't have PCIe reset GPIO. */
  251. if (imx6_pcie->reset_gpio) {
  252. gpiod_set_value_cansleep(imx6_pcie->reset_gpio, 0);
  253. msleep(100);
  254. gpiod_set_value_cansleep(imx6_pcie->reset_gpio, 1);
  255. }
  256. return 0;
  257. err_pcie:
  258. clk_disable_unprepare(imx6_pcie->pcie_bus);
  259. err_pcie_bus:
  260. clk_disable_unprepare(imx6_pcie->pcie_phy);
  261. err_pcie_phy:
  262. return ret;
  263. }
  264. static void imx6_pcie_init_phy(struct pcie_port *pp)
  265. {
  266. struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
  267. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
  268. IMX6Q_GPR12_PCIE_CTL_2, 0 << 10);
  269. /* configure constant input signal to the pcie ctrl and phy */
  270. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
  271. IMX6Q_GPR12_DEVICE_TYPE, PCI_EXP_TYPE_ROOT_PORT << 12);
  272. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
  273. IMX6Q_GPR12_LOS_LEVEL, 9 << 4);
  274. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
  275. IMX6Q_GPR8_TX_DEEMPH_GEN1,
  276. imx6_pcie->tx_deemph_gen1 << 0);
  277. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
  278. IMX6Q_GPR8_TX_DEEMPH_GEN2_3P5DB,
  279. imx6_pcie->tx_deemph_gen2_3p5db << 6);
  280. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
  281. IMX6Q_GPR8_TX_DEEMPH_GEN2_6DB,
  282. imx6_pcie->tx_deemph_gen2_6db << 12);
  283. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
  284. IMX6Q_GPR8_TX_SWING_FULL,
  285. imx6_pcie->tx_swing_full << 18);
  286. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
  287. IMX6Q_GPR8_TX_SWING_LOW,
  288. imx6_pcie->tx_swing_low << 25);
  289. }
  290. static int imx6_pcie_wait_for_link(struct pcie_port *pp)
  291. {
  292. /* check if the link is up or not */
  293. if (!dw_pcie_wait_for_link(pp))
  294. return 0;
  295. dev_dbg(pp->dev, "DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n",
  296. readl(pp->dbi_base + PCIE_PHY_DEBUG_R0),
  297. readl(pp->dbi_base + PCIE_PHY_DEBUG_R1));
  298. return -ETIMEDOUT;
  299. }
  300. static int imx6_pcie_wait_for_speed_change(struct pcie_port *pp)
  301. {
  302. u32 tmp;
  303. unsigned int retries;
  304. for (retries = 0; retries < 200; retries++) {
  305. tmp = readl(pp->dbi_base + PCIE_LINK_WIDTH_SPEED_CONTROL);
  306. /* Test if the speed change finished. */
  307. if (!(tmp & PORT_LOGIC_SPEED_CHANGE))
  308. return 0;
  309. usleep_range(100, 1000);
  310. }
  311. dev_err(pp->dev, "Speed change timeout\n");
  312. return -EINVAL;
  313. }
  314. static irqreturn_t imx6_pcie_msi_handler(int irq, void *arg)
  315. {
  316. struct pcie_port *pp = arg;
  317. return dw_handle_msi_irq(pp);
  318. }
  319. static int imx6_pcie_establish_link(struct pcie_port *pp)
  320. {
  321. struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
  322. u32 tmp;
  323. int ret;
  324. /*
  325. * Force Gen1 operation when starting the link. In case the link is
  326. * started in Gen2 mode, there is a possibility the devices on the
  327. * bus will not be detected at all. This happens with PCIe switches.
  328. */
  329. tmp = readl(pp->dbi_base + PCIE_RC_LCR);
  330. tmp &= ~PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK;
  331. tmp |= PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1;
  332. writel(tmp, pp->dbi_base + PCIE_RC_LCR);
  333. /* Start LTSSM. */
  334. regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
  335. IMX6Q_GPR12_PCIE_CTL_2, 1 << 10);
  336. ret = imx6_pcie_wait_for_link(pp);
  337. if (ret) {
  338. dev_info(pp->dev, "Link never came up\n");
  339. goto err_reset_phy;
  340. }
  341. /* Allow Gen2 mode after the link is up. */
  342. tmp = readl(pp->dbi_base + PCIE_RC_LCR);
  343. tmp &= ~PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK;
  344. tmp |= PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2;
  345. writel(tmp, pp->dbi_base + PCIE_RC_LCR);
  346. /*
  347. * Start Directed Speed Change so the best possible speed both link
  348. * partners support can be negotiated.
  349. */
  350. tmp = readl(pp->dbi_base + PCIE_LINK_WIDTH_SPEED_CONTROL);
  351. tmp |= PORT_LOGIC_SPEED_CHANGE;
  352. writel(tmp, pp->dbi_base + PCIE_LINK_WIDTH_SPEED_CONTROL);
  353. ret = imx6_pcie_wait_for_speed_change(pp);
  354. if (ret) {
  355. dev_err(pp->dev, "Failed to bring link up!\n");
  356. goto err_reset_phy;
  357. }
  358. /* Make sure link training is finished as well! */
  359. ret = imx6_pcie_wait_for_link(pp);
  360. if (ret) {
  361. dev_err(pp->dev, "Failed to bring link up!\n");
  362. goto err_reset_phy;
  363. }
  364. tmp = readl(pp->dbi_base + PCIE_RC_LCSR);
  365. dev_dbg(pp->dev, "Link up, Gen=%i\n", (tmp >> 16) & 0xf);
  366. return 0;
  367. err_reset_phy:
  368. dev_dbg(pp->dev, "PHY DEBUG_R0=0x%08x DEBUG_R1=0x%08x\n",
  369. readl(pp->dbi_base + PCIE_PHY_DEBUG_R0),
  370. readl(pp->dbi_base + PCIE_PHY_DEBUG_R1));
  371. imx6_pcie_reset_phy(pp);
  372. return ret;
  373. }
  374. static void imx6_pcie_host_init(struct pcie_port *pp)
  375. {
  376. imx6_pcie_assert_core_reset(pp);
  377. imx6_pcie_init_phy(pp);
  378. imx6_pcie_deassert_core_reset(pp);
  379. dw_pcie_setup_rc(pp);
  380. imx6_pcie_establish_link(pp);
  381. if (IS_ENABLED(CONFIG_PCI_MSI))
  382. dw_pcie_msi_init(pp);
  383. }
  384. static int imx6_pcie_link_up(struct pcie_port *pp)
  385. {
  386. return readl(pp->dbi_base + PCIE_PHY_DEBUG_R1) &
  387. PCIE_PHY_DEBUG_R1_XMLH_LINK_UP;
  388. }
  389. static struct pcie_host_ops imx6_pcie_host_ops = {
  390. .link_up = imx6_pcie_link_up,
  391. .host_init = imx6_pcie_host_init,
  392. };
  393. static int __init imx6_add_pcie_port(struct pcie_port *pp,
  394. struct platform_device *pdev)
  395. {
  396. int ret;
  397. if (IS_ENABLED(CONFIG_PCI_MSI)) {
  398. pp->msi_irq = platform_get_irq_byname(pdev, "msi");
  399. if (pp->msi_irq <= 0) {
  400. dev_err(&pdev->dev, "failed to get MSI irq\n");
  401. return -ENODEV;
  402. }
  403. ret = devm_request_irq(&pdev->dev, pp->msi_irq,
  404. imx6_pcie_msi_handler,
  405. IRQF_SHARED | IRQF_NO_THREAD,
  406. "mx6-pcie-msi", pp);
  407. if (ret) {
  408. dev_err(&pdev->dev, "failed to request MSI irq\n");
  409. return ret;
  410. }
  411. }
  412. pp->root_bus_nr = -1;
  413. pp->ops = &imx6_pcie_host_ops;
  414. ret = dw_pcie_host_init(pp);
  415. if (ret) {
  416. dev_err(&pdev->dev, "failed to initialize host\n");
  417. return ret;
  418. }
  419. return 0;
  420. }
  421. static int __init imx6_pcie_probe(struct platform_device *pdev)
  422. {
  423. struct imx6_pcie *imx6_pcie;
  424. struct pcie_port *pp;
  425. struct resource *dbi_base;
  426. struct device_node *node = pdev->dev.of_node;
  427. int ret;
  428. imx6_pcie = devm_kzalloc(&pdev->dev, sizeof(*imx6_pcie), GFP_KERNEL);
  429. if (!imx6_pcie)
  430. return -ENOMEM;
  431. pp = &imx6_pcie->pp;
  432. pp->dev = &pdev->dev;
  433. /* Added for PCI abort handling */
  434. hook_fault_code(16 + 6, imx6q_pcie_abort_handler, SIGBUS, 0,
  435. "imprecise external abort");
  436. dbi_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  437. pp->dbi_base = devm_ioremap_resource(&pdev->dev, dbi_base);
  438. if (IS_ERR(pp->dbi_base))
  439. return PTR_ERR(pp->dbi_base);
  440. /* Fetch GPIOs */
  441. imx6_pcie->reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
  442. GPIOD_OUT_LOW);
  443. /* Fetch clocks */
  444. imx6_pcie->pcie_phy = devm_clk_get(&pdev->dev, "pcie_phy");
  445. if (IS_ERR(imx6_pcie->pcie_phy)) {
  446. dev_err(&pdev->dev,
  447. "pcie_phy clock source missing or invalid\n");
  448. return PTR_ERR(imx6_pcie->pcie_phy);
  449. }
  450. imx6_pcie->pcie_bus = devm_clk_get(&pdev->dev, "pcie_bus");
  451. if (IS_ERR(imx6_pcie->pcie_bus)) {
  452. dev_err(&pdev->dev,
  453. "pcie_bus clock source missing or invalid\n");
  454. return PTR_ERR(imx6_pcie->pcie_bus);
  455. }
  456. imx6_pcie->pcie = devm_clk_get(&pdev->dev, "pcie");
  457. if (IS_ERR(imx6_pcie->pcie)) {
  458. dev_err(&pdev->dev,
  459. "pcie clock source missing or invalid\n");
  460. return PTR_ERR(imx6_pcie->pcie);
  461. }
  462. /* Grab GPR config register range */
  463. imx6_pcie->iomuxc_gpr =
  464. syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
  465. if (IS_ERR(imx6_pcie->iomuxc_gpr)) {
  466. dev_err(&pdev->dev, "unable to find iomuxc registers\n");
  467. return PTR_ERR(imx6_pcie->iomuxc_gpr);
  468. }
  469. /* Grab PCIe PHY Tx Settings */
  470. if (of_property_read_u32(node, "fsl,tx-deemph-gen1",
  471. &imx6_pcie->tx_deemph_gen1))
  472. imx6_pcie->tx_deemph_gen1 = 0;
  473. if (of_property_read_u32(node, "fsl,tx-deemph-gen2-3p5db",
  474. &imx6_pcie->tx_deemph_gen2_3p5db))
  475. imx6_pcie->tx_deemph_gen2_3p5db = 0;
  476. if (of_property_read_u32(node, "fsl,tx-deemph-gen2-6db",
  477. &imx6_pcie->tx_deemph_gen2_6db))
  478. imx6_pcie->tx_deemph_gen2_6db = 20;
  479. if (of_property_read_u32(node, "fsl,tx-swing-full",
  480. &imx6_pcie->tx_swing_full))
  481. imx6_pcie->tx_swing_full = 127;
  482. if (of_property_read_u32(node, "fsl,tx-swing-low",
  483. &imx6_pcie->tx_swing_low))
  484. imx6_pcie->tx_swing_low = 127;
  485. ret = imx6_add_pcie_port(pp, pdev);
  486. if (ret < 0)
  487. return ret;
  488. platform_set_drvdata(pdev, imx6_pcie);
  489. return 0;
  490. }
  491. static void imx6_pcie_shutdown(struct platform_device *pdev)
  492. {
  493. struct imx6_pcie *imx6_pcie = platform_get_drvdata(pdev);
  494. /* bring down link, so bootloader gets clean state in case of reboot */
  495. imx6_pcie_assert_core_reset(&imx6_pcie->pp);
  496. }
  497. static const struct of_device_id imx6_pcie_of_match[] = {
  498. { .compatible = "fsl,imx6q-pcie", },
  499. {},
  500. };
  501. MODULE_DEVICE_TABLE(of, imx6_pcie_of_match);
  502. static struct platform_driver imx6_pcie_driver = {
  503. .driver = {
  504. .name = "imx6q-pcie",
  505. .of_match_table = imx6_pcie_of_match,
  506. },
  507. .shutdown = imx6_pcie_shutdown,
  508. };
  509. /* Freescale PCIe driver does not allow module unload */
  510. static int __init imx6_pcie_init(void)
  511. {
  512. return platform_driver_probe(&imx6_pcie_driver, imx6_pcie_probe);
  513. }
  514. module_init(imx6_pcie_init);
  515. MODULE_AUTHOR("Sean Cross <xobs@kosagi.com>");
  516. MODULE_DESCRIPTION("Freescale i.MX6 PCIe host controller driver");
  517. MODULE_LICENSE("GPL v2");