Blame view
drivers/pci/pcie_imx.c
44.2 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
e9be4292e ARM: mx6: Add PCI... |
2 3 4 5 6 |
/* * Freescale i.MX6 PCI Express Root-Complex driver * * Copyright (C) 2013 Marek Vasut <marex@denx.de> * |
2fed8187f ENGR00325255 pcie... |
7 |
* Copyright (C) 2014-2016 Freescale Semiconductor, Inc. |
344e04ed3 MLK-22398-1 pcie_... |
8 |
* Copyright 2019 NXP |
2fed8187f ENGR00325255 pcie... |
9 |
* |
e9be4292e ARM: mx6: Add PCI... |
10 11 12 |
* Based on upstream Linux kernel driver: * pci-imx6.c: Sean Cross <xobs@kosagi.com> * pcie-designware.c: Jingoo Han <jg1.han@samsung.com> |
e9be4292e ARM: mx6: Add PCI... |
13 14 15 |
*/ #include <common.h> |
2cf431c22 common: Move pci_... |
16 |
#include <init.h> |
336d4615f dm: core: Create ... |
17 |
#include <malloc.h> |
e9be4292e ARM: mx6: Add PCI... |
18 |
#include <pci.h> |
344e04ed3 MLK-22398-1 pcie_... |
19 20 21 |
#if CONFIG_IS_ENABLED(CLK) #include <clk.h> #else |
e9be4292e ARM: mx6: Add PCI... |
22 |
#include <asm/arch/clock.h> |
344e04ed3 MLK-22398-1 pcie_... |
23 |
#endif |
e9be4292e ARM: mx6: Add PCI... |
24 |
#include <asm/arch/iomux.h> |
344e04ed3 MLK-22398-1 pcie_... |
25 |
#ifdef CONFIG_MX6 |
e9be4292e ARM: mx6: Add PCI... |
26 |
#include <asm/arch/crm_regs.h> |
344e04ed3 MLK-22398-1 pcie_... |
27 |
#endif |
bb0195634 pci: mx6: Impleme... |
28 |
#include <asm/gpio.h> |
e9be4292e ARM: mx6: Add PCI... |
29 |
#include <asm/io.h> |
a11c0f44b pci: imx: Add DM ... |
30 |
#include <dm.h> |
1ace40223 sizes.h - consoli... |
31 |
#include <linux/sizes.h> |
344e04ed3 MLK-22398-1 pcie_... |
32 |
#include <linux/ioport.h> |
e9be4292e ARM: mx6: Add PCI... |
33 |
#include <errno.h> |
aaf87f03a pci: pcie_imx: Fi... |
34 |
#include <asm/arch/sys_proto.h> |
344e04ed3 MLK-22398-1 pcie_... |
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#include <syscon.h> #include <regmap.h> #include <asm-generic/gpio.h> #include <dt-bindings/soc/imx8_hsio.h> #include <power/regulator.h> #include <dm/device_compat.h> enum imx_pcie_variants { IMX6Q, IMX6SX, IMX6QP, IMX8QM, IMX8QXP, }; |
e9be4292e ARM: mx6: Add PCI... |
49 50 51 |
#define PCI_ACCESS_READ 0 #define PCI_ACCESS_WRITE 1 |
1b8ad74a6 pcie_imx: Add mx6... |
52 53 |
#ifdef CONFIG_MX6SX #define MX6_DBI_ADDR 0x08ffc000 |
344e04ed3 MLK-22398-1 pcie_... |
54 55 |
#define MX6_IO_ADDR 0x08f80000 #define MX6_MEM_ADDR 0x08000000 |
1b8ad74a6 pcie_imx: Add mx6... |
56 57 |
#define MX6_ROOT_ADDR 0x08f00000 #else |
e9be4292e ARM: mx6: Add PCI... |
58 |
#define MX6_DBI_ADDR 0x01ffc000 |
344e04ed3 MLK-22398-1 pcie_... |
59 60 |
#define MX6_IO_ADDR 0x01f80000 #define MX6_MEM_ADDR 0x01000000 |
e9be4292e ARM: mx6: Add PCI... |
61 |
#define MX6_ROOT_ADDR 0x01f00000 |
1b8ad74a6 pcie_imx: Add mx6... |
62 63 |
#endif #define MX6_DBI_SIZE 0x4000 |
344e04ed3 MLK-22398-1 pcie_... |
64 65 66 |
#define MX6_IO_SIZE 0x10000 #define MX6_MEM_SIZE 0xf00000 #define MX6_ROOT_SIZE 0x80000 |
e9be4292e ARM: mx6: Add PCI... |
67 68 69 |
/* PCIe Port Logic registers (memory-mapped) */ #define PL_OFFSET 0x700 |
6ecbe1375 drivers: pci: imx... |
70 71 72 |
#define PCIE_PL_PFLR (PL_OFFSET + 0x08) #define PCIE_PL_PFLR_LINK_STATE_MASK (0x3f << 16) #define PCIE_PL_PFLR_FORCE_LINK (1 << 15) |
e9be4292e ARM: mx6: Add PCI... |
73 74 75 76 |
#define PCIE_PHY_DEBUG_R0 (PL_OFFSET + 0x28) #define PCIE_PHY_DEBUG_R1 (PL_OFFSET + 0x2c) #define PCIE_PHY_DEBUG_R1_LINK_UP (1 << 4) #define PCIE_PHY_DEBUG_R1_LINK_IN_TRAINING (1 << 29) |
344e04ed3 MLK-22398-1 pcie_... |
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
#define PCIE_PORT_LINK_CONTROL 0x710 #define PORT_LINK_MODE_MASK (0x3f << 16) #define PORT_LINK_MODE_1_LANES (0x1 << 16) #define PORT_LINK_MODE_2_LANES (0x3 << 16) #define PORT_LINK_MODE_4_LANES (0x7 << 16) #define PORT_LINK_MODE_8_LANES (0xf << 16) #define PCIE_LINK_WIDTH_SPEED_CONTROL 0x80C #define PORT_LOGIC_SPEED_CHANGE (0x1 << 17) #define PORT_LOGIC_LINK_WIDTH_MASK (0x1f << 8) #define PORT_LOGIC_LINK_WIDTH_1_LANES (0x1 << 8) #define PORT_LOGIC_LINK_WIDTH_2_LANES (0x2 << 8) #define PORT_LOGIC_LINK_WIDTH_4_LANES (0x4 << 8) #define PORT_LOGIC_LINK_WIDTH_8_LANES (0x8 << 8) |
e9be4292e ARM: mx6: Add PCI... |
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
#define PCIE_PHY_CTRL (PL_OFFSET + 0x114) #define PCIE_PHY_CTRL_DATA_LOC 0 #define PCIE_PHY_CTRL_CAP_ADR_LOC 16 #define PCIE_PHY_CTRL_CAP_DAT_LOC 17 #define PCIE_PHY_CTRL_WR_LOC 18 #define PCIE_PHY_CTRL_RD_LOC 19 #define PCIE_PHY_STAT (PL_OFFSET + 0x110) #define PCIE_PHY_STAT_DATA_LOC 0 #define PCIE_PHY_STAT_ACK_LOC 16 /* PHY registers (not memory-mapped) */ #define PCIE_PHY_RX_ASIC_OUT 0x100D #define PHY_RX_OVRD_IN_LO 0x1005 #define PHY_RX_OVRD_IN_LO_RX_DATA_EN (1 << 5) #define PHY_RX_OVRD_IN_LO_RX_PLL_EN (1 << 3) |
1b8ad74a6 pcie_imx: Add mx6... |
109 |
#define PCIE_PHY_PUP_REQ (1 << 7) |
e9be4292e ARM: mx6: Add PCI... |
110 111 112 113 |
/* iATU registers */ #define PCIE_ATU_VIEWPORT 0x900 #define PCIE_ATU_REGION_INBOUND (0x1 << 31) #define PCIE_ATU_REGION_OUTBOUND (0x0 << 31) |
344e04ed3 MLK-22398-1 pcie_... |
114 |
#define PCIE_ATU_REGION_INDEX2 (0x2 << 0) |
e9be4292e ARM: mx6: Add PCI... |
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
#define PCIE_ATU_REGION_INDEX1 (0x1 << 0) #define PCIE_ATU_REGION_INDEX0 (0x0 << 0) #define PCIE_ATU_CR1 0x904 #define PCIE_ATU_TYPE_MEM (0x0 << 0) #define PCIE_ATU_TYPE_IO (0x2 << 0) #define PCIE_ATU_TYPE_CFG0 (0x4 << 0) #define PCIE_ATU_TYPE_CFG1 (0x5 << 0) #define PCIE_ATU_CR2 0x908 #define PCIE_ATU_ENABLE (0x1 << 31) #define PCIE_ATU_BAR_MODE_ENABLE (0x1 << 30) #define PCIE_ATU_LOWER_BASE 0x90C #define PCIE_ATU_UPPER_BASE 0x910 #define PCIE_ATU_LIMIT 0x914 #define PCIE_ATU_LOWER_TARGET 0x918 #define PCIE_ATU_BUS(x) (((x) & 0xff) << 24) #define PCIE_ATU_DEV(x) (((x) & 0x1f) << 19) #define PCIE_ATU_FUNC(x) (((x) & 0x7) << 16) #define PCIE_ATU_UPPER_TARGET 0x91C |
344e04ed3 MLK-22398-1 pcie_... |
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
#define PCIE_MISC_CTRL (PL_OFFSET + 0x1BC) #define PCIE_MISC_DBI_RO_WR_EN BIT(0) /* iMX8 HSIO registers */ #define IMX8QM_LPCG_PHYX2_OFFSET 0x00000 #define IMX8QM_CSR_PHYX2_OFFSET 0x90000 #define IMX8QM_CSR_PHYX1_OFFSET 0xA0000 #define IMX8QM_CSR_PHYX_STTS0_OFFSET 0x4 #define IMX8QM_CSR_PCIEA_OFFSET 0xB0000 #define IMX8QM_CSR_PCIEB_OFFSET 0xC0000 #define IMX8QM_CSR_PCIE_CTRL1_OFFSET 0x4 #define IMX8QM_CSR_PCIE_CTRL2_OFFSET 0x8 #define IMX8QM_CSR_PCIE_STTS0_OFFSET 0xC #define IMX8QM_CSR_MISC_OFFSET 0xE0000 #define IMX8QM_LPCG_PHY_PCG0 BIT(1) #define IMX8QM_LPCG_PHY_PCG1 BIT(5) #define IMX8QM_CTRL_LTSSM_ENABLE BIT(4) #define IMX8QM_CTRL_READY_ENTR_L23 BIT(5) #define IMX8QM_CTRL_PM_XMT_TURNOFF BIT(9) #define IMX8QM_CTRL_BUTTON_RST_N BIT(21) #define IMX8QM_CTRL_PERST_N BIT(22) #define IMX8QM_CTRL_POWER_UP_RST_N BIT(23) #define IMX8QM_CTRL_STTS0_PM_LINKST_IN_L2 BIT(13) #define IMX8QM_CTRL_STTS0_PM_REQ_CORE_RST BIT(19) #define IMX8QM_STTS0_LANE0_TX_PLL_LOCK BIT(4) #define IMX8QM_STTS0_LANE1_TX_PLL_LOCK BIT(12) #define IMX8QM_PCIE_TYPE_MASK (0xF << 24) #define IMX8QM_PHYX2_CTRL0_APB_MASK 0x3 #define IMX8QM_PHY_APB_RSTN_0 BIT(0) #define IMX8QM_PHY_APB_RSTN_1 BIT(1) #define IMX8QM_MISC_IOB_RXENA BIT(0) #define IMX8QM_MISC_IOB_TXENA BIT(1) #define IMX8QM_CSR_MISC_IOB_A_0_TXOE BIT(2) #define IMX8QM_CSR_MISC_IOB_A_0_M1M0_MASK (0x3 << 3) #define IMX8QM_CSR_MISC_IOB_A_0_M1M0_2 BIT(4) #define IMX8QM_MISC_PHYX1_EPCS_SEL BIT(12) #define IMX8QM_MISC_PCIE_AB_SELECT BIT(13) #define HW_PHYX2_CTRL0_PIPE_LN2LK_MASK (0xF << 13) #define HW_PHYX2_CTRL0_PIPE_LN2LK_0 BIT(13) #define HW_PHYX2_CTRL0_PIPE_LN2LK_1 BIT(14) #define HW_PHYX2_CTRL0_PIPE_LN2LK_2 BIT(15) #define HW_PHYX2_CTRL0_PIPE_LN2LK_3 BIT(16) #define PHY_PLL_LOCK_WAIT_MAX_RETRIES 2000 |
33f794be3 pci: imx: Factor ... |
184 |
|
2fed8187f ENGR00325255 pcie... |
185 186 187 188 189 190 191 192 193 194 |
#ifdef DEBUG #ifdef DEBUG_STRESS_WR /* warm-reset stress tests */ #define SNVS_LPGRP 0x020cc068 #endif #define DBGF(x...) printf(x) static void print_regs(int contain_pcie_reg) { |
344e04ed3 MLK-22398-1 pcie_... |
195 |
#ifdef CONFIG_MX6 |
2fed8187f ENGR00325255 pcie... |
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
u32 val; struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; struct mxc_ccm_reg *ccm_regs = (struct mxc_ccm_reg *)CCM_BASE_ADDR; val = readl(&iomuxc_regs->gpr[1]); DBGF("GPR01 a:0x%08x v:0x%08x ", (u32)&iomuxc_regs->gpr[1], val); val = readl(&iomuxc_regs->gpr[5]); DBGF("GPR05 a:0x%08x v:0x%08x ", (u32)&iomuxc_regs->gpr[5], val); val = readl(&iomuxc_regs->gpr[8]); DBGF("GPR08 a:0x%08x v:0x%08x ", (u32)&iomuxc_regs->gpr[8], val); val = readl(&iomuxc_regs->gpr[12]); DBGF("GPR12 a:0x%08x v:0x%08x ", (u32)&iomuxc_regs->gpr[12], val); val = readl(&ccm_regs->analog_pll_enet); DBGF("PLL06 a:0x%08x v:0x%08x ", (u32)&ccm_regs->analog_pll_enet, val); val = readl(&ccm_regs->ana_misc1); DBGF("MISC1 a:0x%08x v:0x%08x ", (u32)&ccm_regs->ana_misc1, val); if (contain_pcie_reg) { val = readl(MX6_DBI_ADDR + 0x728); DBGF("dbr0 offset 0x728 %08x ", val); val = readl(MX6_DBI_ADDR + 0x72c); DBGF("dbr1 offset 0x72c %08x ", val); } |
344e04ed3 MLK-22398-1 pcie_... |
225 |
#endif |
2fed8187f ENGR00325255 pcie... |
226 227 228 229 230 |
} #else #define DBGF(x...) static void print_regs(int contain_pcie_reg) {} #endif |
344e04ed3 MLK-22398-1 pcie_... |
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
struct imx_pcie_priv { void __iomem *dbi_base; void __iomem *cfg_base; void __iomem *cfg1_base; enum imx_pcie_variants variant; struct regmap *iomuxc_gpr; u32 hsio_cfg; u32 ctrl_id; u32 ext_osc; u32 cpu_base; u32 lanes; u32 cfg_size; int cpu_addr_offset; struct gpio_desc clkreq_gpio; struct gpio_desc dis_gpio; struct gpio_desc reset_gpio; struct gpio_desc power_on_gpio; struct pci_region *io; struct pci_region *mem; struct pci_region *pref; #if CONFIG_IS_ENABLED(CLK) struct clk pcie_bus; struct clk pcie_phy; struct clk pcie_inbound_axi; struct clk pcie_per; struct clk phy_per; struct clk misc_per; struct clk pcie; struct clk pcie_ext_src; #endif #if CONFIG_IS_ENABLED(DM_REGULATOR) struct udevice *epdev_on; struct udevice *pcie_bus_regulator; struct udevice *pcie_phy_regulator; #endif }; |
e9be4292e ARM: mx6: Add PCI... |
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
/* * PHY access functions */ static int pcie_phy_poll_ack(void __iomem *dbi_base, int exp_val) { u32 val; u32 max_iterations = 10; u32 wait_counter = 0; do { val = readl(dbi_base + PCIE_PHY_STAT); val = (val >> PCIE_PHY_STAT_ACK_LOC) & 0x1; wait_counter++; if (val == exp_val) return 0; udelay(1); } while (wait_counter < max_iterations); return -ETIMEDOUT; } static int pcie_phy_wait_ack(void __iomem *dbi_base, int addr) { u32 val; int ret; val = addr << PCIE_PHY_CTRL_DATA_LOC; writel(val, dbi_base + PCIE_PHY_CTRL); val |= (0x1 << PCIE_PHY_CTRL_CAP_ADR_LOC); writel(val, dbi_base + PCIE_PHY_CTRL); ret = pcie_phy_poll_ack(dbi_base, 1); if (ret) return ret; val = addr << PCIE_PHY_CTRL_DATA_LOC; writel(val, dbi_base + PCIE_PHY_CTRL); ret = pcie_phy_poll_ack(dbi_base, 0); if (ret) return ret; return 0; } /* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */ static int pcie_phy_read(void __iomem *dbi_base, int addr , int *data) { u32 val, phy_ctl; int ret; ret = pcie_phy_wait_ack(dbi_base, addr); if (ret) return ret; /* assert Read signal */ phy_ctl = 0x1 << PCIE_PHY_CTRL_RD_LOC; writel(phy_ctl, dbi_base + PCIE_PHY_CTRL); ret = pcie_phy_poll_ack(dbi_base, 1); if (ret) return ret; val = readl(dbi_base + PCIE_PHY_STAT); *data = val & 0xffff; /* deassert Read signal */ writel(0x00, dbi_base + PCIE_PHY_CTRL); ret = pcie_phy_poll_ack(dbi_base, 0); if (ret) return ret; return 0; } static int pcie_phy_write(void __iomem *dbi_base, int addr, int data) { u32 var; int ret; /* write addr */ /* cap addr */ ret = pcie_phy_wait_ack(dbi_base, addr); if (ret) return ret; var = data << PCIE_PHY_CTRL_DATA_LOC; writel(var, dbi_base + PCIE_PHY_CTRL); /* capture data */ var |= (0x1 << PCIE_PHY_CTRL_CAP_DAT_LOC); writel(var, dbi_base + PCIE_PHY_CTRL); ret = pcie_phy_poll_ack(dbi_base, 1); if (ret) return ret; /* deassert cap data */ var = data << PCIE_PHY_CTRL_DATA_LOC; writel(var, dbi_base + PCIE_PHY_CTRL); /* wait for ack de-assertion */ ret = pcie_phy_poll_ack(dbi_base, 0); if (ret) return ret; /* assert wr signal */ var = 0x1 << PCIE_PHY_CTRL_WR_LOC; writel(var, dbi_base + PCIE_PHY_CTRL); /* wait for ack */ ret = pcie_phy_poll_ack(dbi_base, 1); if (ret) return ret; /* deassert wr signal */ var = data << PCIE_PHY_CTRL_DATA_LOC; writel(var, dbi_base + PCIE_PHY_CTRL); /* wait for ack de-assertion */ ret = pcie_phy_poll_ack(dbi_base, 0); if (ret) return ret; writel(0x0, dbi_base + PCIE_PHY_CTRL); return 0; } |
344e04ed3 MLK-22398-1 pcie_... |
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
#if !CONFIG_IS_ENABLED(DM_PCI) void imx_pcie_gpr_read(struct imx_pcie_priv *priv, uint offset, uint *valp) { struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; *valp = readl(&iomuxc_regs->gpr[offset >> 2]); } void imx_pcie_gpr_update_bits(struct imx_pcie_priv *priv, uint offset, uint mask, uint val) { struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; clrsetbits_32(&iomuxc_regs->gpr[offset >> 2], mask, val); } #else void imx_pcie_gpr_read(struct imx_pcie_priv *priv, uint offset, uint *valp) { regmap_read(priv->iomuxc_gpr, offset, valp); } void imx_pcie_gpr_update_bits(struct imx_pcie_priv *priv, uint offset, uint mask, uint val) { regmap_update_bits(priv->iomuxc_gpr, offset, mask, val); } #endif |
d2cc2e86f pci: imx: Pass dr... |
427 |
static int imx6_pcie_link_up(struct imx_pcie_priv *priv) |
e9be4292e ARM: mx6: Add PCI... |
428 429 430 431 432 |
{ u32 rc, ltssm; int rx_valid, temp; /* link is debug bit 36, debug register 1 starts at bit 32 */ |
33f794be3 pci: imx: Factor ... |
433 |
rc = readl(priv->dbi_base + PCIE_PHY_DEBUG_R1); |
e9be4292e ARM: mx6: Add PCI... |
434 435 436 437 438 439 440 441 442 443 444 |
if ((rc & PCIE_PHY_DEBUG_R1_LINK_UP) && !(rc & PCIE_PHY_DEBUG_R1_LINK_IN_TRAINING)) return -EAGAIN; /* * From L0, initiate MAC entry to gen2 if EP/RC supports gen2. * Wait 2ms (LTSSM timeout is 24ms, PHY lock is ~5us in gen2). * If (MAC/LTSSM.state == Recovery.RcvrLock) * && (PHY/rx_valid==0) then pulse PHY/rx_reset. Transition * to gen2 is stuck */ |
33f794be3 pci: imx: Factor ... |
445 446 |
pcie_phy_read(priv->dbi_base, PCIE_PHY_RX_ASIC_OUT, &rx_valid); ltssm = readl(priv->dbi_base + PCIE_PHY_DEBUG_R0) & 0x3F; |
e9be4292e ARM: mx6: Add PCI... |
447 448 449 450 451 452 453 454 455 |
if (rx_valid & 0x01) return 0; if (ltssm != 0x0d) return 0; printf("transition to gen2 is stuck, reset PHY! "); |
33f794be3 pci: imx: Factor ... |
456 |
pcie_phy_read(priv->dbi_base, PHY_RX_OVRD_IN_LO, &temp); |
e9be4292e ARM: mx6: Add PCI... |
457 |
temp |= (PHY_RX_OVRD_IN_LO_RX_DATA_EN | PHY_RX_OVRD_IN_LO_RX_PLL_EN); |
33f794be3 pci: imx: Factor ... |
458 |
pcie_phy_write(priv->dbi_base, PHY_RX_OVRD_IN_LO, temp); |
e9be4292e ARM: mx6: Add PCI... |
459 460 |
udelay(3000); |
33f794be3 pci: imx: Factor ... |
461 |
pcie_phy_read(priv->dbi_base, PHY_RX_OVRD_IN_LO, &temp); |
e9be4292e ARM: mx6: Add PCI... |
462 |
temp &= ~(PHY_RX_OVRD_IN_LO_RX_DATA_EN | PHY_RX_OVRD_IN_LO_RX_PLL_EN); |
33f794be3 pci: imx: Factor ... |
463 |
pcie_phy_write(priv->dbi_base, PHY_RX_OVRD_IN_LO, temp); |
e9be4292e ARM: mx6: Add PCI... |
464 465 466 |
return 0; } |
344e04ed3 MLK-22398-1 pcie_... |
467 468 |
/* Fix class value */ static void imx_pcie_fix_class(struct imx_pcie_priv *priv) |
e9be4292e ARM: mx6: Add PCI... |
469 |
{ |
344e04ed3 MLK-22398-1 pcie_... |
470 471 |
writew(PCI_CLASS_BRIDGE_PCI, priv->dbi_base + PCI_CLASS_DEVICE); } |
e9be4292e ARM: mx6: Add PCI... |
472 |
|
344e04ed3 MLK-22398-1 pcie_... |
473 474 475 476 477 |
/* Clear multi-function bit */ static void imx_pcie_clear_multifunction(struct imx_pcie_priv *priv) { writeb(PCI_HEADER_TYPE_BRIDGE, priv->dbi_base + PCI_HEADER_TYPE); } |
e9be4292e ARM: mx6: Add PCI... |
478 |
|
344e04ed3 MLK-22398-1 pcie_... |
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
static void imx_pcie_setup_ctrl(struct imx_pcie_priv *priv) { u32 val; writel(PCIE_MISC_DBI_RO_WR_EN, priv->dbi_base + PCIE_MISC_CTRL); /* Set the number of lanes */ val = readl(priv->dbi_base + PCIE_PORT_LINK_CONTROL); val &= ~PORT_LINK_MODE_MASK; switch (priv->lanes) { case 1: val |= PORT_LINK_MODE_1_LANES; break; case 2: val |= PORT_LINK_MODE_2_LANES; break; case 4: val |= PORT_LINK_MODE_4_LANES; break; case 8: val |= PORT_LINK_MODE_8_LANES; break; default: printf("num-lanes %u: invalid value ", priv->lanes); return; } writel(val, priv->dbi_base + PCIE_PORT_LINK_CONTROL); /* Set link width speed control register */ val = readl(priv->dbi_base + PCIE_LINK_WIDTH_SPEED_CONTROL); val &= ~PORT_LOGIC_LINK_WIDTH_MASK; switch (priv->lanes) { case 1: val |= PORT_LOGIC_LINK_WIDTH_1_LANES; break; case 2: val |= PORT_LOGIC_LINK_WIDTH_2_LANES; break; case 4: val |= PORT_LOGIC_LINK_WIDTH_4_LANES; break; case 8: val |= PORT_LOGIC_LINK_WIDTH_8_LANES; break; } writel(val, priv->dbi_base + PCIE_LINK_WIDTH_SPEED_CONTROL); |
e9be4292e ARM: mx6: Add PCI... |
526 |
|
344e04ed3 MLK-22398-1 pcie_... |
527 528 529 |
/* setup RC BARs */ writel(0, priv->dbi_base + PCI_BASE_ADDRESS_0); writel(0, priv->dbi_base + PCI_BASE_ADDRESS_1); |
e9be4292e ARM: mx6: Add PCI... |
530 |
|
344e04ed3 MLK-22398-1 pcie_... |
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
/* setup bus numbers */ val = readl(priv->dbi_base + PCI_PRIMARY_BUS); val &= 0xff000000; val |= 0x00ff0100; writel(val, priv->dbi_base + PCI_PRIMARY_BUS); /* setup command register */ val = readl(priv->dbi_base + PCI_COMMAND); val &= 0xffff0000; val |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; writel(val, priv->dbi_base + PCI_COMMAND); imx_pcie_fix_class(priv); imx_pcie_clear_multifunction(priv); writel(0, priv->dbi_base + PCIE_MISC_CTRL); } |
e9be4292e ARM: mx6: Add PCI... |
549 |
|
344e04ed3 MLK-22398-1 pcie_... |
550 551 552 553 554 555 556 557 558 559 |
static void imx_pcie_atu_outbound_set(struct imx_pcie_priv *priv, int idx, int type, u64 phys, u64 bus_addr, u32 size) { writel(PCIE_ATU_REGION_OUTBOUND | idx, priv->dbi_base + PCIE_ATU_VIEWPORT); writel((u32)(phys + priv->cpu_addr_offset), priv->dbi_base + PCIE_ATU_LOWER_BASE); writel((phys + priv->cpu_addr_offset) >> 32, priv->dbi_base + PCIE_ATU_UPPER_BASE); writel((u32)(phys + priv->cpu_addr_offset) + size - 1, priv->dbi_base + PCIE_ATU_LIMIT); writel((u32)bus_addr, priv->dbi_base + PCIE_ATU_LOWER_TARGET); writel(bus_addr >> 32, priv->dbi_base + PCIE_ATU_UPPER_TARGET); writel(type, priv->dbi_base + PCIE_ATU_CR1); |
33f794be3 pci: imx: Factor ... |
560 |
writel(PCIE_ATU_ENABLE, priv->dbi_base + PCIE_ATU_CR2); |
344e04ed3 MLK-22398-1 pcie_... |
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
} /* * iATU region setup */ static int imx_pcie_regions_setup(struct imx_pcie_priv *priv) { if (priv->io) /* ATU : OUTBOUND : IO */ imx_pcie_atu_outbound_set(priv, PCIE_ATU_REGION_INDEX2, PCIE_ATU_TYPE_IO, priv->io->phys_start, priv->io->bus_start, priv->io->size); if (priv->mem) /* ATU : OUTBOUND : MEM */ imx_pcie_atu_outbound_set(priv, PCIE_ATU_REGION_INDEX0, PCIE_ATU_TYPE_MEM, priv->mem->phys_start, priv->mem->bus_start, priv->mem->size); |
e9be4292e ARM: mx6: Add PCI... |
583 584 585 586 587 588 589 |
return 0; } /* * PCI Express accessors */ |
d2cc2e86f pci: imx: Pass dr... |
590 591 |
static void __iomem *get_bus_address(struct imx_pcie_priv *priv, pci_dev_t d, int where) |
e9be4292e ARM: mx6: Add PCI... |
592 |
{ |
90f87fb52 pci: imx: Fix pot... |
593 |
void __iomem *va_address; |
e9be4292e ARM: mx6: Add PCI... |
594 |
|
e9be4292e ARM: mx6: Add PCI... |
595 |
if (PCI_BUS(d) == 0) { |
344e04ed3 MLK-22398-1 pcie_... |
596 |
/* Outbound TLP matched primary interface of the bridge */ |
90f87fb52 pci: imx: Fix pot... |
597 |
va_address = priv->dbi_base; |
e9be4292e ARM: mx6: Add PCI... |
598 |
} else { |
344e04ed3 MLK-22398-1 pcie_... |
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 |
if (PCI_BUS(d) < 2) { /* Outbound TLP matched secondary interface of the bridge changes to CFG0 */ imx_pcie_atu_outbound_set(priv, PCIE_ATU_REGION_INDEX1, PCIE_ATU_TYPE_CFG0, (ulong)priv->cfg_base, d << 8, priv->cfg_size >> 1); va_address = priv->cfg_base; } else { /* Outbound TLP matched the bus behind the bridge uses type CFG1 */ imx_pcie_atu_outbound_set(priv, PCIE_ATU_REGION_INDEX1, PCIE_ATU_TYPE_CFG1, (ulong)priv->cfg1_base, d << 8, priv->cfg_size >> 1); va_address = priv->cfg1_base; } |
e9be4292e ARM: mx6: Add PCI... |
616 617 618 619 620 |
} va_address += (where & ~0x3); return va_address; |
344e04ed3 MLK-22398-1 pcie_... |
621 |
|
e9be4292e ARM: mx6: Add PCI... |
622 623 624 625 |
} static int imx_pcie_addr_valid(pci_dev_t d) { |
344e04ed3 MLK-22398-1 pcie_... |
626 |
if ((PCI_BUS(d) == 0) && (PCI_DEV(d) > 0)) |
e9be4292e ARM: mx6: Add PCI... |
627 |
return -EINVAL; |
344e04ed3 MLK-22398-1 pcie_... |
628 |
/* ARI forward is not enabled, so non-zero device at downstream must be blocked */ |
e9be4292e ARM: mx6: Add PCI... |
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 |
if ((PCI_BUS(d) == 1) && (PCI_DEV(d) > 0)) return -EINVAL; return 0; } /* * Replace the original ARM DABT handler with a simple jump-back one. * * The problem here is that if we have a PCIe bridge attached to this PCIe * controller, but no PCIe device is connected to the bridges' downstream * port, the attempt to read/write from/to the config space will produce * a DABT. This is a behavior of the controller and can not be disabled * unfortuatelly. * * To work around the problem, we backup the current DABT handler address * and replace it with our own DABT handler, which only bounces right back * into the code. */ static void imx_pcie_fix_dabt_handler(bool set) { |
344e04ed3 MLK-22398-1 pcie_... |
649 |
#ifdef CONFIG_MX6 |
e9be4292e ARM: mx6: Add PCI... |
650 651 652 653 654 655 656 657 658 659 660 661 662 663 |
extern uint32_t *_data_abort; uint32_t *data_abort_addr = (uint32_t *)&_data_abort; static const uint32_t data_abort_bounce_handler = 0xe25ef004; uint32_t data_abort_bounce_addr = (uint32_t)&data_abort_bounce_handler; static uint32_t data_abort_backup; if (set) { data_abort_backup = *data_abort_addr; *data_abort_addr = data_abort_bounce_addr; } else { *data_abort_addr = data_abort_backup; } |
344e04ed3 MLK-22398-1 pcie_... |
664 |
#endif |
e9be4292e ARM: mx6: Add PCI... |
665 |
} |
a11c0f44b pci: imx: Add DM ... |
666 667 |
static int imx_pcie_read_cfg(struct imx_pcie_priv *priv, pci_dev_t d, int where, u32 *val) |
e9be4292e ARM: mx6: Add PCI... |
668 |
{ |
90f87fb52 pci: imx: Fix pot... |
669 |
void __iomem *va_address; |
e9be4292e ARM: mx6: Add PCI... |
670 671 672 673 674 |
int ret; ret = imx_pcie_addr_valid(d); if (ret) { *val = 0xffffffff; |
344e04ed3 MLK-22398-1 pcie_... |
675 |
return 0; |
e9be4292e ARM: mx6: Add PCI... |
676 |
} |
d2cc2e86f pci: imx: Pass dr... |
677 |
va_address = get_bus_address(priv, d, where); |
e9be4292e ARM: mx6: Add PCI... |
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
/* * Read the PCIe config space. We must replace the DABT handler * here in case we got data abort from the PCIe controller, see * imx_pcie_fix_dabt_handler() description. Note that writing the * "val" with valid value is also imperative here as in case we * did got DABT, the val would contain random value. */ imx_pcie_fix_dabt_handler(true); writel(0xffffffff, val); *val = readl(va_address); imx_pcie_fix_dabt_handler(false); return 0; } |
a11c0f44b pci: imx: Add DM ... |
693 694 |
static int imx_pcie_write_cfg(struct imx_pcie_priv *priv, pci_dev_t d, int where, u32 val) |
e9be4292e ARM: mx6: Add PCI... |
695 |
{ |
90f87fb52 pci: imx: Fix pot... |
696 |
void __iomem *va_address = NULL; |
e9be4292e ARM: mx6: Add PCI... |
697 698 699 700 701 |
int ret; ret = imx_pcie_addr_valid(d); if (ret) return ret; |
d2cc2e86f pci: imx: Pass dr... |
702 |
va_address = get_bus_address(priv, d, where); |
e9be4292e ARM: mx6: Add PCI... |
703 704 705 706 707 708 709 710 711 712 713 714 |
/* * Write the PCIe config space. We must replace the DABT handler * here in case we got data abort from the PCIe controller, see * imx_pcie_fix_dabt_handler() description. */ imx_pcie_fix_dabt_handler(true); writel(val, va_address); imx_pcie_fix_dabt_handler(false); return 0; } |
344e04ed3 MLK-22398-1 pcie_... |
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 |
static int imx8_pcie_assert_core_reset(struct imx_pcie_priv *priv, bool prepare_for_boot) { u32 val; switch (priv->variant) { case IMX8QXP: val = IMX8QM_CSR_PCIEB_OFFSET; imx_pcie_gpr_update_bits(priv, val + IMX8QM_CSR_PCIE_CTRL2_OFFSET, IMX8QM_CTRL_BUTTON_RST_N, IMX8QM_CTRL_BUTTON_RST_N); imx_pcie_gpr_update_bits(priv, val + IMX8QM_CSR_PCIE_CTRL2_OFFSET, IMX8QM_CTRL_PERST_N, IMX8QM_CTRL_PERST_N); imx_pcie_gpr_update_bits(priv, val + IMX8QM_CSR_PCIE_CTRL2_OFFSET, IMX8QM_CTRL_POWER_UP_RST_N, IMX8QM_CTRL_POWER_UP_RST_N); break; case IMX8QM: val = IMX8QM_CSR_PCIEA_OFFSET + priv->ctrl_id * SZ_64K; imx_pcie_gpr_update_bits(priv, val + IMX8QM_CSR_PCIE_CTRL2_OFFSET, IMX8QM_CTRL_BUTTON_RST_N, IMX8QM_CTRL_BUTTON_RST_N); imx_pcie_gpr_update_bits(priv, val + IMX8QM_CSR_PCIE_CTRL2_OFFSET, IMX8QM_CTRL_PERST_N, IMX8QM_CTRL_PERST_N); imx_pcie_gpr_update_bits(priv, val + IMX8QM_CSR_PCIE_CTRL2_OFFSET, IMX8QM_CTRL_POWER_UP_RST_N, IMX8QM_CTRL_POWER_UP_RST_N); break; default: break; } return 0; } static int imx8_pcie_init_phy(struct imx_pcie_priv *priv) { u32 tmp, val; if (priv->variant == IMX8QM || priv->variant == IMX8QXP) { switch (priv->hsio_cfg) { case PCIEAX2SATA: /* * bit 0 rx ena 1. * bit12 PHY_X1_EPCS_SEL 1. * bit13 phy_ab_select 0. */ imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_PHYX2_OFFSET, IMX8QM_PHYX2_CTRL0_APB_MASK, IMX8QM_PHY_APB_RSTN_0 | IMX8QM_PHY_APB_RSTN_1); imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_MISC_OFFSET, IMX8QM_MISC_PHYX1_EPCS_SEL, IMX8QM_MISC_PHYX1_EPCS_SEL); imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_MISC_OFFSET, IMX8QM_MISC_PCIE_AB_SELECT, 0); break; case PCIEAX1PCIEBX1SATA: tmp = IMX8QM_PHY_APB_RSTN_1; tmp |= IMX8QM_PHY_APB_RSTN_0; imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_PHYX2_OFFSET, IMX8QM_PHYX2_CTRL0_APB_MASK, tmp); imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_MISC_OFFSET, IMX8QM_MISC_PHYX1_EPCS_SEL, IMX8QM_MISC_PHYX1_EPCS_SEL); imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_MISC_OFFSET, IMX8QM_MISC_PCIE_AB_SELECT, IMX8QM_MISC_PCIE_AB_SELECT); imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_PHYX2_OFFSET, HW_PHYX2_CTRL0_PIPE_LN2LK_MASK, HW_PHYX2_CTRL0_PIPE_LN2LK_3 | HW_PHYX2_CTRL0_PIPE_LN2LK_0); break; case PCIEAX2PCIEBX1: /* * bit 0 rx ena 1. * bit12 PHY_X1_EPCS_SEL 0. * bit13 phy_ab_select 1. */ if (priv->ctrl_id) imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_PHYX1_OFFSET, IMX8QM_PHY_APB_RSTN_0, IMX8QM_PHY_APB_RSTN_0); else imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_PHYX2_OFFSET, IMX8QM_PHYX2_CTRL0_APB_MASK, IMX8QM_PHY_APB_RSTN_0 | IMX8QM_PHY_APB_RSTN_1); imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_MISC_OFFSET, IMX8QM_MISC_PHYX1_EPCS_SEL, 0); imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_MISC_OFFSET, IMX8QM_MISC_PCIE_AB_SELECT, IMX8QM_MISC_PCIE_AB_SELECT); break; } if (priv->ext_osc) { imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_MISC_OFFSET, IMX8QM_MISC_IOB_RXENA, IMX8QM_MISC_IOB_RXENA); imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_MISC_OFFSET, IMX8QM_MISC_IOB_TXENA, 0); } else { /* Try to used the internal pll as ref clk */ imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_MISC_OFFSET, IMX8QM_MISC_IOB_RXENA, 0); imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_MISC_OFFSET, IMX8QM_MISC_IOB_TXENA, IMX8QM_MISC_IOB_TXENA); imx_pcie_gpr_update_bits(priv, IMX8QM_CSR_MISC_OFFSET, IMX8QM_CSR_MISC_IOB_A_0_TXOE | IMX8QM_CSR_MISC_IOB_A_0_M1M0_MASK, IMX8QM_CSR_MISC_IOB_A_0_TXOE | IMX8QM_CSR_MISC_IOB_A_0_M1M0_2); } val = IMX8QM_CSR_PCIEA_OFFSET + priv->ctrl_id * SZ_64K; imx_pcie_gpr_update_bits(priv, val, IMX8QM_PCIE_TYPE_MASK, 0x4 << 24); mdelay(10); } return 0; } static int imx8_pcie_wait_for_phy_pll_lock(struct imx_pcie_priv *priv) { u32 val, tmp, orig; unsigned int retries = 0; if (priv->variant == IMX8QXP || priv->variant == IMX8QM) { for (retries = 0; retries < PHY_PLL_LOCK_WAIT_MAX_RETRIES; retries++) { if (priv->hsio_cfg == PCIEAX1PCIEBX1SATA) { imx_pcie_gpr_read(priv, IMX8QM_CSR_PHYX2_OFFSET + 0x4, &tmp); if (priv->ctrl_id == 0) /* pciea 1 lanes */ orig = IMX8QM_STTS0_LANE0_TX_PLL_LOCK; else /* pcieb 1 lanes */ orig = IMX8QM_STTS0_LANE1_TX_PLL_LOCK; tmp &= orig; if (tmp == orig) { imx_pcie_gpr_update_bits(priv, IMX8QM_LPCG_PHYX2_OFFSET, IMX8QM_LPCG_PHY_PCG0 | IMX8QM_LPCG_PHY_PCG1, IMX8QM_LPCG_PHY_PCG0 | IMX8QM_LPCG_PHY_PCG1); break; } } if (priv->hsio_cfg == PCIEAX2PCIEBX1) { val = IMX8QM_CSR_PHYX2_OFFSET + priv->ctrl_id * SZ_64K; imx_pcie_gpr_read(priv, val + IMX8QM_CSR_PHYX_STTS0_OFFSET, &tmp); orig = IMX8QM_STTS0_LANE0_TX_PLL_LOCK; if (priv->ctrl_id == 0) /* pciea 2 lanes */ orig |= IMX8QM_STTS0_LANE1_TX_PLL_LOCK; tmp &= orig; if (tmp == orig) { val = IMX8QM_CSR_PHYX2_OFFSET + priv->ctrl_id * SZ_64K; imx_pcie_gpr_update_bits(priv, val, IMX8QM_LPCG_PHY_PCG0, IMX8QM_LPCG_PHY_PCG0); break; } } udelay(10); } } if (retries >= PHY_PLL_LOCK_WAIT_MAX_RETRIES) { printf("pcie phy pll can't be locked. "); return -ENODEV; } else { debug("pcie phy pll is locked. "); return 0; } } static int imx8_pcie_deassert_core_reset(struct imx_pcie_priv *priv) { int ret, i; u32 val, tmp; #if CONFIG_IS_ENABLED(CLK) ret = clk_enable(&priv->pcie); if (ret) { printf("unable to enable pcie clock "); return ret; } ret = clk_enable(&priv->pcie_phy); if (ret) { printf("unable to enable pcie_phy clock "); goto err_pcie; } #endif if (priv->variant == IMX8QM || priv->variant == IMX8QXP) { #if CONFIG_IS_ENABLED(CLK) ret = clk_enable(&priv->pcie_inbound_axi); if (ret) { printf("unable to enable pcie_axi clock "); goto err_pcie_phy; } ret = clk_enable(&priv->pcie_per); if (ret) { printf("unable to enable pcie_per clock "); clk_disable(&priv->pcie_inbound_axi); goto err_pcie_phy; } #endif /* allow the clocks to stabilize */ udelay(200); /* bit19 PM_REQ_CORE_RST of pciex#_stts0 should be cleared. */ for (i = 0; i < 100; i++) { val = IMX8QM_CSR_PCIEA_OFFSET + priv->ctrl_id * SZ_64K; imx_pcie_gpr_read(priv, val + IMX8QM_CSR_PCIE_STTS0_OFFSET, &tmp); if ((tmp & IMX8QM_CTRL_STTS0_PM_REQ_CORE_RST) == 0) break; udelay(10); } if ((tmp & IMX8QM_CTRL_STTS0_PM_REQ_CORE_RST) != 0) printf("ERROR PM_REQ_CORE_RST is still set. "); /* wait for phy pll lock firstly. */ if (imx8_pcie_wait_for_phy_pll_lock(priv)) { ret = -ENODEV; goto err_ref_clk;; } if (dm_gpio_is_valid(&priv->reset_gpio)) { dm_gpio_set_value(&priv->reset_gpio, 1); mdelay(20); dm_gpio_set_value(&priv->reset_gpio, 0); mdelay(20); } return 0; } err_ref_clk: #if CONFIG_IS_ENABLED(CLK) clk_disable(&priv->pcie_per); clk_disable(&priv->pcie_inbound_axi); err_pcie_phy: clk_disable(&priv->pcie_phy); err_pcie: clk_disable(&priv->pcie); #endif return ret; } #ifdef CONFIG_MX6 |
e9be4292e ARM: mx6: Add PCI... |
1029 1030 1031 |
/* * Initial bus setup */ |
d2cc2e86f pci: imx: Pass dr... |
1032 1033 |
static int imx6_pcie_assert_core_reset(struct imx_pcie_priv *priv, bool prepare_for_boot) |
e9be4292e ARM: mx6: Add PCI... |
1034 |
{ |
344e04ed3 MLK-22398-1 pcie_... |
1035 1036 |
if (priv->variant == IMX6QP) imx_pcie_gpr_update_bits(priv, 4, IOMUXC_GPR1_PCIE_SW_RST, IOMUXC_GPR1_PCIE_SW_RST); |
aaf87f03a pci: pcie_imx: Fi... |
1037 |
|
1b8ad74a6 pcie_imx: Add mx6... |
1038 |
#if defined(CONFIG_MX6SX) |
344e04ed3 MLK-22398-1 pcie_... |
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 |
if (priv->variant == IMX6SX) { struct gpc *gpc_regs = (struct gpc *)GPC_BASE_ADDR; /* SSP_EN is not used on MX6SX anymore */ imx_pcie_gpr_update_bits(priv, 48, IOMUXC_GPR12_TEST_POWERDOWN, IOMUXC_GPR12_TEST_POWERDOWN); /* Force PCIe PHY reset */ imx_pcie_gpr_update_bits(priv, 20, IOMUXC_GPR5_PCIE_BTNRST, IOMUXC_GPR5_PCIE_BTNRST); /* Power up PCIe PHY */ setbits_le32(&gpc_regs->cntr, PCIE_PHY_PUP_REQ); pcie_power_up(); return 0; } #endif |
6ecbe1375 drivers: pci: imx... |
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 |
/* * If the bootloader already enabled the link we need some special * handling to get the core back into a state where it is safe to * touch it for configuration. As there is no dedicated reset signal * wired up for MX6QDL, we need to manually force LTSSM into "detect" * state before completely disabling LTSSM, which is a prerequisite * for core configuration. * * If both LTSSM_ENABLE and REF_SSP_ENABLE are active we have a strong * indication that the bootloader activated the link. */ |
0f630e17a MLK-24042-2 pci: ... |
1064 |
if (priv->variant == IMX6Q && prepare_for_boot) { |
6ecbe1375 drivers: pci: imx... |
1065 |
u32 val, gpr1, gpr12; |
344e04ed3 MLK-22398-1 pcie_... |
1066 1067 |
imx_pcie_gpr_read(priv, 4, &gpr1); imx_pcie_gpr_read(priv, 48, &gpr12); |
6ecbe1375 drivers: pci: imx... |
1068 1069 |
if ((gpr1 & IOMUXC_GPR1_PCIE_REF_CLK_EN) && (gpr12 & IOMUXC_GPR12_PCIE_CTL_2)) { |
33f794be3 pci: imx: Factor ... |
1070 |
val = readl(priv->dbi_base + PCIE_PL_PFLR); |
6ecbe1375 drivers: pci: imx... |
1071 1072 1073 1074 |
val &= ~PCIE_PL_PFLR_LINK_STATE_MASK; val |= PCIE_PL_PFLR_FORCE_LINK; imx_pcie_fix_dabt_handler(true); |
33f794be3 pci: imx: Factor ... |
1075 |
writel(val, priv->dbi_base + PCIE_PL_PFLR); |
6ecbe1375 drivers: pci: imx... |
1076 |
imx_pcie_fix_dabt_handler(false); |
344e04ed3 MLK-22398-1 pcie_... |
1077 |
imx_pcie_gpr_update_bits(priv, 48, IOMUXC_GPR12_PCIE_CTL_2, 0); |
6ecbe1375 drivers: pci: imx... |
1078 1079 |
} } |
344e04ed3 MLK-22398-1 pcie_... |
1080 1081 1082 1083 1084 1085 |
if (priv->variant == IMX6QP || priv->variant == IMX6Q) { imx_pcie_gpr_update_bits(priv, 4, IOMUXC_GPR1_TEST_POWERDOWN, IOMUXC_GPR1_TEST_POWERDOWN); imx_pcie_gpr_update_bits(priv, 4, IOMUXC_GPR1_REF_SSP_EN, 0); } |
e9be4292e ARM: mx6: Add PCI... |
1086 1087 1088 |
return 0; } |
344e04ed3 MLK-22398-1 pcie_... |
1089 |
static int imx6_pcie_init_phy(struct imx_pcie_priv *priv) |
e9be4292e ARM: mx6: Add PCI... |
1090 |
{ |
2fed8187f ENGR00325255 pcie... |
1091 |
#ifndef DEBUG |
344e04ed3 MLK-22398-1 pcie_... |
1092 |
imx_pcie_gpr_update_bits(priv, 48, IOMUXC_GPR12_APPS_LTSSM_ENABLE, 0); |
2fed8187f ENGR00325255 pcie... |
1093 |
#endif |
e9be4292e ARM: mx6: Add PCI... |
1094 |
|
344e04ed3 MLK-22398-1 pcie_... |
1095 |
imx_pcie_gpr_update_bits(priv, 48, |
e9be4292e ARM: mx6: Add PCI... |
1096 1097 |
IOMUXC_GPR12_DEVICE_TYPE_MASK, IOMUXC_GPR12_DEVICE_TYPE_RC); |
344e04ed3 MLK-22398-1 pcie_... |
1098 |
imx_pcie_gpr_update_bits(priv, 48, |
e9be4292e ARM: mx6: Add PCI... |
1099 1100 |
IOMUXC_GPR12_LOS_LEVEL_MASK, IOMUXC_GPR12_LOS_LEVEL_9); |
344e04ed3 MLK-22398-1 pcie_... |
1101 1102 1103 1104 1105 |
if (priv->variant == IMX6SX) { imx_pcie_gpr_update_bits(priv, 48, IOMUXC_GPR12_RX_EQ_MASK, IOMUXC_GPR12_RX_EQ_2); } |
1b8ad74a6 pcie_imx: Add mx6... |
1106 |
|
344e04ed3 MLK-22398-1 pcie_... |
1107 1108 |
imx_pcie_gpr_update_bits(priv, 32, 0xffffffff, (0x0 << IOMUXC_GPR8_PCS_TX_DEEMPH_GEN1_OFFSET) | |
e9be4292e ARM: mx6: Add PCI... |
1109 1110 1111 |
(0x0 << IOMUXC_GPR8_PCS_TX_DEEMPH_GEN2_3P5DB_OFFSET) | (20 << IOMUXC_GPR8_PCS_TX_DEEMPH_GEN2_6DB_OFFSET) | (127 << IOMUXC_GPR8_PCS_TX_SWING_FULL_OFFSET) | |
344e04ed3 MLK-22398-1 pcie_... |
1112 |
(127 << IOMUXC_GPR8_PCS_TX_SWING_LOW_OFFSET)); |
e9be4292e ARM: mx6: Add PCI... |
1113 1114 1115 |
return 0; } |
a778aeae0 pci: mx6: Impleme... |
1116 1117 1118 |
__weak int imx6_pcie_toggle_power(void) { #ifdef CONFIG_PCIE_IMX_POWER_GPIO |
67b71df27 pci: imx: request... |
1119 |
gpio_request(CONFIG_PCIE_IMX_POWER_GPIO, "pcie_power"); |
a778aeae0 pci: mx6: Impleme... |
1120 1121 1122 1123 |
gpio_direction_output(CONFIG_PCIE_IMX_POWER_GPIO, 0); mdelay(20); gpio_set_value(CONFIG_PCIE_IMX_POWER_GPIO, 1); mdelay(20); |
67b71df27 pci: imx: request... |
1124 |
gpio_free(CONFIG_PCIE_IMX_POWER_GPIO); |
a778aeae0 pci: mx6: Impleme... |
1125 1126 1127 |
#endif return 0; } |
bb0195634 pci: mx6: Impleme... |
1128 1129 1130 1131 1132 1133 1134 1135 |
__weak int imx6_pcie_toggle_reset(void) { /* * See 'PCI EXPRESS BASE SPECIFICATION, REV 3.0, SECTION 6.6.1' * for detailed understanding of the PCIe CR reset logic. * * The PCIe #PERST reset line _MUST_ be connected, otherwise your * design does not conform to the specification. You must wait at |
8f6edf6d3 pcie_imx: Use 'ms... |
1136 |
* least 20 ms after de-asserting the #PERST so the EP device can |
bb0195634 pci: mx6: Impleme... |
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 |
* do self-initialisation. * * In case your #PERST pin is connected to a plain GPIO pin of the * CPU, you can define CONFIG_PCIE_IMX_PERST_GPIO in your board's * configuration file and the condition below will handle the rest * of the reset toggling. * * In case your #PERST toggling logic is more complex, for example * connected via CPLD or somesuch, you can override this function * in your board file and implement reset logic as needed. You must |
8f6edf6d3 pcie_imx: Use 'ms... |
1147 |
* not forget to wait at least 20 ms after de-asserting #PERST in |
bb0195634 pci: mx6: Impleme... |
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 |
* this case either though. * * In case your #PERST line of the PCIe EP device is not connected * at all, your design is broken and you should fix your design, * otherwise you will observe problems like for example the link * not coming up after rebooting the system back from running Linux * that uses the PCIe as well OR the PCIe link might not come up in * Linux at all in the first place since it's in some non-reset * state due to being previously used in U-Boot. */ #ifdef CONFIG_PCIE_IMX_PERST_GPIO |
67b71df27 pci: imx: request... |
1159 |
gpio_request(CONFIG_PCIE_IMX_PERST_GPIO, "pcie_reset"); |
bb0195634 pci: mx6: Impleme... |
1160 1161 1162 1163 |
gpio_direction_output(CONFIG_PCIE_IMX_PERST_GPIO, 0); mdelay(20); gpio_set_value(CONFIG_PCIE_IMX_PERST_GPIO, 1); mdelay(20); |
67b71df27 pci: imx: request... |
1164 |
gpio_free(CONFIG_PCIE_IMX_PERST_GPIO); |
bb0195634 pci: mx6: Impleme... |
1165 1166 1167 1168 |
#else puts("WARNING: Make sure the PCIe #PERST line is connected! "); #endif |
344e04ed3 MLK-22398-1 pcie_... |
1169 |
|
bb0195634 pci: mx6: Impleme... |
1170 1171 |
return 0; } |
344e04ed3 MLK-22398-1 pcie_... |
1172 |
static int imx6_pcie_deassert_core_reset(struct imx_pcie_priv *priv) |
e9be4292e ARM: mx6: Add PCI... |
1173 |
{ |
344e04ed3 MLK-22398-1 pcie_... |
1174 |
#if !CONFIG_IS_ENABLED(DM_PCI) |
a778aeae0 pci: mx6: Impleme... |
1175 |
imx6_pcie_toggle_power(); |
344e04ed3 MLK-22398-1 pcie_... |
1176 |
#endif |
e9be4292e ARM: mx6: Add PCI... |
1177 |
|
e9be4292e ARM: mx6: Add PCI... |
1178 |
enable_pcie_clock(); |
344e04ed3 MLK-22398-1 pcie_... |
1179 1180 |
if (priv->variant == IMX6QP) imx_pcie_gpr_update_bits(priv, 4, IOMUXC_GPR1_PCIE_SW_RST, 0); |
aaf87f03a pci: pcie_imx: Fi... |
1181 |
|
e9be4292e ARM: mx6: Add PCI... |
1182 1183 |
/* * Wait for the clock to settle a bit, when the clock are sourced |
8f6edf6d3 pcie_imx: Use 'ms... |
1184 |
* from the CPU, we need about 30 ms to settle. |
e9be4292e ARM: mx6: Add PCI... |
1185 |
*/ |
bb0195634 pci: mx6: Impleme... |
1186 |
mdelay(50); |
e9be4292e ARM: mx6: Add PCI... |
1187 |
|
344e04ed3 MLK-22398-1 pcie_... |
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 |
if (priv->variant == IMX6SX) { /* SSP_EN is not used on MX6SX anymore */ imx_pcie_gpr_update_bits(priv, 48, IOMUXC_GPR12_TEST_POWERDOWN, 0); /* Clear PCIe PHY reset bit */ imx_pcie_gpr_update_bits(priv, 20, IOMUXC_GPR5_PCIE_BTNRST, 0); } else { /* Enable PCIe */ imx_pcie_gpr_update_bits(priv, 4, IOMUXC_GPR1_TEST_POWERDOWN, 0); imx_pcie_gpr_update_bits(priv, 4, IOMUXC_GPR1_REF_SSP_EN, IOMUXC_GPR1_REF_SSP_EN); } |
5a82e1a21 pci: mx6: fix occ... |
1198 |
|
344e04ed3 MLK-22398-1 pcie_... |
1199 |
#if !CONFIG_IS_ENABLED(DM_PCI) |
bb0195634 pci: mx6: Impleme... |
1200 |
imx6_pcie_toggle_reset(); |
344e04ed3 MLK-22398-1 pcie_... |
1201 1202 1203 1204 1205 1206 1207 1208 |
#else if (dm_gpio_is_valid(&priv->reset_gpio)) { dm_gpio_set_value(&priv->reset_gpio, 1); mdelay(20); dm_gpio_set_value(&priv->reset_gpio, 0); mdelay(20); } #endif |
e9be4292e ARM: mx6: Add PCI... |
1209 1210 1211 |
return 0; } |
344e04ed3 MLK-22398-1 pcie_... |
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 |
#endif static int imx_pcie_assert_core_reset(struct imx_pcie_priv *priv, bool prepare_for_boot) { switch (priv->variant) { #ifdef CONFIG_MX6 case IMX6Q: case IMX6QP: case IMX6SX: return imx6_pcie_assert_core_reset(priv, prepare_for_boot); #endif case IMX8QM: case IMX8QXP: return imx8_pcie_assert_core_reset(priv, prepare_for_boot); default: return -EPERM; } } static int imx_pcie_init_phy(struct imx_pcie_priv *priv) { switch (priv->variant) { #ifdef CONFIG_MX6 case IMX6Q: case IMX6QP: case IMX6SX: return imx6_pcie_init_phy(priv); #endif case IMX8QM: case IMX8QXP: return imx8_pcie_init_phy(priv); default: return -EPERM; } } static int imx_pcie_deassert_core_reset(struct imx_pcie_priv *priv) { switch (priv->variant) { #ifdef CONFIG_MX6 case IMX6Q: case IMX6QP: case IMX6SX: return imx6_pcie_deassert_core_reset(priv); #endif case IMX8QM: case IMX8QXP: return imx8_pcie_deassert_core_reset(priv); default: return -EPERM; } } static void imx_pcie_ltssm_enable(struct imx_pcie_priv *priv, bool enable) { u32 val; switch (priv->variant) { #ifdef CONFIG_MX6 case IMX6Q: case IMX6SX: case IMX6QP: if (enable) imx_pcie_gpr_update_bits(priv, 48, IOMUXC_GPR12_APPS_LTSSM_ENABLE, IOMUXC_GPR12_APPS_LTSSM_ENABLE); /* LTSSM enable, starting link. */ else imx_pcie_gpr_update_bits(priv, 48, IOMUXC_GPR12_APPS_LTSSM_ENABLE, 0); break; #endif case IMX8QXP: case IMX8QM: /* Bit4 of the CTRL2 */ val = IMX8QM_CSR_PCIEA_OFFSET + priv->ctrl_id * SZ_64K; if (enable) { imx_pcie_gpr_update_bits(priv, val + IMX8QM_CSR_PCIE_CTRL2_OFFSET, IMX8QM_CTRL_LTSSM_ENABLE, IMX8QM_CTRL_LTSSM_ENABLE); } else { imx_pcie_gpr_update_bits(priv, val + IMX8QM_CSR_PCIE_CTRL2_OFFSET, IMX8QM_CTRL_LTSSM_ENABLE, 0); } break; default: break; } } |
e9be4292e ARM: mx6: Add PCI... |
1305 |
|
d2cc2e86f pci: imx: Pass dr... |
1306 |
static int imx_pcie_link_up(struct imx_pcie_priv *priv) |
e9be4292e ARM: mx6: Add PCI... |
1307 |
{ |
e9be4292e ARM: mx6: Add PCI... |
1308 1309 |
uint32_t tmp; int count = 0; |
344e04ed3 MLK-22398-1 pcie_... |
1310 1311 1312 |
imx_pcie_assert_core_reset(priv, false); imx_pcie_init_phy(priv); imx_pcie_deassert_core_reset(priv); |
e9be4292e ARM: mx6: Add PCI... |
1313 |
|
344e04ed3 MLK-22398-1 pcie_... |
1314 |
imx_pcie_setup_ctrl(priv); |
d2cc2e86f pci: imx: Pass dr... |
1315 |
imx_pcie_regions_setup(priv); |
e9be4292e ARM: mx6: Add PCI... |
1316 1317 |
/* |
f57263ee9 drivers: pci: imx... |
1318 1319 1320 1321 1322 1323 |
* By default, the subordinate is set equally to the secondary * bus (0x01) when the RC boots. * This means that theoretically, only bus 1 is reachable from the RC. * Force the PCIe RC subordinate to 0xff, otherwise no downstream * devices will be detected if the enumeration is applied strictly. */ |
33f794be3 pci: imx: Factor ... |
1324 |
tmp = readl(priv->dbi_base + 0x18); |
f57263ee9 drivers: pci: imx... |
1325 |
tmp |= (0xff << 16); |
33f794be3 pci: imx: Factor ... |
1326 |
writel(tmp, priv->dbi_base + 0x18); |
f57263ee9 drivers: pci: imx... |
1327 1328 |
/* |
e9be4292e ARM: mx6: Add PCI... |
1329 1330 1331 1332 1333 |
* FIXME: Force the PCIe RC to Gen1 operation * The RC must be forced into Gen1 mode before bringing the link * up, otherwise no downstream devices are detected. After the * link is up, a managed Gen1->Gen2 transition can be initiated. */ |
33f794be3 pci: imx: Factor ... |
1334 |
tmp = readl(priv->dbi_base + 0x7c); |
e9be4292e ARM: mx6: Add PCI... |
1335 1336 |
tmp &= ~0xf; tmp |= 0x1; |
33f794be3 pci: imx: Factor ... |
1337 |
writel(tmp, priv->dbi_base + 0x7c); |
e9be4292e ARM: mx6: Add PCI... |
1338 1339 |
/* LTSSM enable, starting link. */ |
344e04ed3 MLK-22398-1 pcie_... |
1340 |
imx_pcie_ltssm_enable(priv, true); |
e9be4292e ARM: mx6: Add PCI... |
1341 |
|
d2cc2e86f pci: imx: Pass dr... |
1342 |
while (!imx6_pcie_link_up(priv)) { |
e9be4292e ARM: mx6: Add PCI... |
1343 1344 |
udelay(10); count++; |
2fed8187f ENGR00325255 pcie... |
1345 1346 1347 1348 1349 |
if (count == 1000) { print_regs(1); /* link down, try reset ep, and re-try link here */ DBGF("pcie link is down, reset ep, then retry! "); |
344e04ed3 MLK-22398-1 pcie_... |
1350 1351 1352 1353 1354 1355 1356 1357 1358 |
#if CONFIG_IS_ENABLED(DM_PCI) if (dm_gpio_is_valid(&priv->reset_gpio)) { dm_gpio_set_value(&priv->reset_gpio, 1); mdelay(20); dm_gpio_set_value(&priv->reset_gpio, 0); mdelay(20); } #elif defined(CONFIG_MX6) |
2fed8187f ENGR00325255 pcie... |
1359 |
imx6_pcie_toggle_reset(); |
344e04ed3 MLK-22398-1 pcie_... |
1360 |
#endif |
2fed8187f ENGR00325255 pcie... |
1361 1362 1363 1364 1365 1366 |
continue; } #ifdef DEBUG else if (count >= 2000) { print_regs(1); /* link is down, stop here */ |
344e04ed3 MLK-22398-1 pcie_... |
1367 |
env_set("bootcmd", "sleep 2;"); |
2fed8187f ENGR00325255 pcie... |
1368 1369 |
DBGF("pcie link is down, stop here! "); |
344e04ed3 MLK-22398-1 pcie_... |
1370 |
imx_pcie_ltssm_enable(priv, false); |
2fed8187f ENGR00325255 pcie... |
1371 1372 1373 |
return -EINVAL; } #endif |
a32b4a03c pcie_imx: increme... |
1374 |
if (count >= 4000) { |
378b02d7e pci: imx: display... |
1375 1376 1377 1378 |
#ifdef CONFIG_PCI_SCAN_SHOW puts("PCI: pcie phy link never came up "); #endif |
e9be4292e ARM: mx6: Add PCI... |
1379 1380 |
debug("DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x ", |
33f794be3 pci: imx: Factor ... |
1381 1382 |
readl(priv->dbi_base + PCIE_PHY_DEBUG_R0), readl(priv->dbi_base + PCIE_PHY_DEBUG_R1)); |
344e04ed3 MLK-22398-1 pcie_... |
1383 |
imx_pcie_ltssm_enable(priv, false); |
e9be4292e ARM: mx6: Add PCI... |
1384 1385 1386 1387 1388 1389 |
return -EINVAL; } } return 0; } |
a11c0f44b pci: imx: Add DM ... |
1390 |
#if !CONFIG_IS_ENABLED(DM_PCI) |
d2cc2e86f pci: imx: Pass dr... |
1391 1392 1393 |
static struct imx_pcie_priv imx_pcie_priv = { .dbi_base = (void __iomem *)MX6_DBI_ADDR, .cfg_base = (void __iomem *)MX6_ROOT_ADDR, |
344e04ed3 MLK-22398-1 pcie_... |
1394 1395 1396 |
.cfg1_base = (void __iomem *)(MX6_ROOT_ADDR + MX6_ROOT_SIZE / 2), .cfg_size = MX6_ROOT_SIZE, .lanes = 1, |
d2cc2e86f pci: imx: Pass dr... |
1397 1398 1399 |
}; static struct imx_pcie_priv *priv = &imx_pcie_priv; |
344e04ed3 MLK-22398-1 pcie_... |
1400 |
|
a11c0f44b pci: imx: Add DM ... |
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 |
static int imx_pcie_read_config(struct pci_controller *hose, pci_dev_t d, int where, u32 *val) { struct imx_pcie_priv *priv = hose->priv_data; return imx_pcie_read_cfg(priv, d, where, val); } static int imx_pcie_write_config(struct pci_controller *hose, pci_dev_t d, int where, u32 val) { struct imx_pcie_priv *priv = hose->priv_data; return imx_pcie_write_cfg(priv, d, where, val); } |
e9be4292e ARM: mx6: Add PCI... |
1416 1417 1418 1419 1420 1421 |
void imx_pcie_init(void) { /* Static instance of the controller. */ static struct pci_controller pcc; struct pci_controller *hose = &pcc; int ret; |
2fed8187f ENGR00325255 pcie... |
1422 1423 1424 1425 |
#ifdef DEBUG_STRESS_WR u32 dbg_reg_addr = SNVS_LPGRP; u32 dbg_reg = readl(dbg_reg_addr) + 1; #endif |
e9be4292e ARM: mx6: Add PCI... |
1426 1427 |
memset(&pcc, 0, sizeof(pcc)); |
344e04ed3 MLK-22398-1 pcie_... |
1428 1429 1430 1431 1432 1433 |
if (is_mx6sx()) priv->variant = IMX6SX; else if (is_mx6dqp()) priv->variant = IMX6QP; else priv->variant = IMX6Q; |
d2cc2e86f pci: imx: Pass dr... |
1434 |
hose->priv_data = priv; |
e9be4292e ARM: mx6: Add PCI... |
1435 1436 |
/* PCI I/O space */ pci_set_region(&hose->regions[0], |
344e04ed3 MLK-22398-1 pcie_... |
1437 |
0, MX6_IO_ADDR, |
e9be4292e ARM: mx6: Add PCI... |
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 |
MX6_IO_SIZE, PCI_REGION_IO); /* PCI memory space */ pci_set_region(&hose->regions[1], MX6_MEM_ADDR, MX6_MEM_ADDR, MX6_MEM_SIZE, PCI_REGION_MEM); /* System memory space */ pci_set_region(&hose->regions[2], MMDC0_ARB_BASE_ADDR, MMDC0_ARB_BASE_ADDR, 0xefffffff, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY); |
344e04ed3 MLK-22398-1 pcie_... |
1449 1450 |
priv->io = &hose->regions[0]; priv->mem = &hose->regions[1]; |
e9be4292e ARM: mx6: Add PCI... |
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 |
hose->region_count = 3; pci_set_ops(hose, pci_hose_read_config_byte_via_dword, pci_hose_read_config_word_via_dword, imx_pcie_read_config, pci_hose_write_config_byte_via_dword, pci_hose_write_config_word_via_dword, imx_pcie_write_config); /* Start the controller. */ |
d2cc2e86f pci: imx: Pass dr... |
1462 |
ret = imx_pcie_link_up(priv); |
e9be4292e ARM: mx6: Add PCI... |
1463 1464 1465 1466 |
if (!ret) { pci_register_hose(hose); hose->last_busno = pci_hose_scan(hose); |
2fed8187f ENGR00325255 pcie... |
1467 1468 1469 |
#ifdef DEBUG_STRESS_WR dbg_reg += 1<<16; #endif |
e9be4292e ARM: mx6: Add PCI... |
1470 |
} |
2fed8187f ENGR00325255 pcie... |
1471 1472 1473 1474 1475 1476 |
#ifdef DEBUG_STRESS_WR writel(dbg_reg, dbg_reg_addr); DBGF("PCIe Successes/Attempts: %d/%d ", dbg_reg >> 16, dbg_reg & 0xffff); #endif |
e9be4292e ARM: mx6: Add PCI... |
1477 |
} |
6ecbe1375 drivers: pci: imx... |
1478 1479 |
void imx_pcie_remove(void) { |
d2cc2e86f pci: imx: Pass dr... |
1480 |
imx6_pcie_assert_core_reset(priv, true); |
6ecbe1375 drivers: pci: imx... |
1481 |
} |
e9be4292e ARM: mx6: Add PCI... |
1482 1483 1484 1485 1486 |
/* Probe function. */ void pci_init_board(void) { imx_pcie_init(); } |
344e04ed3 MLK-22398-1 pcie_... |
1487 1488 1489 1490 1491 |
int pci_skip_dev(struct pci_controller *hose, pci_dev_t dev) { return 0; } |
a11c0f44b pci: imx: Add DM ... |
1492 |
#else |
c4e72c4ad dm: pci: Update t... |
1493 |
static int imx_pcie_dm_read_config(const struct udevice *dev, pci_dev_t bdf, |
a11c0f44b pci: imx: Add DM ... |
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 |
uint offset, ulong *value, enum pci_size_t size) { struct imx_pcie_priv *priv = dev_get_priv(dev); u32 tmpval; int ret; ret = imx_pcie_read_cfg(priv, bdf, offset, &tmpval); if (ret) return ret; *value = pci_conv_32_to_size(tmpval, offset, size); return 0; } static int imx_pcie_dm_write_config(struct udevice *dev, pci_dev_t bdf, uint offset, ulong value, enum pci_size_t size) { struct imx_pcie_priv *priv = dev_get_priv(dev); u32 tmpval, newval; int ret; ret = imx_pcie_read_cfg(priv, bdf, offset, &tmpval); if (ret) return ret; newval = pci_conv_size_to_32(tmpval, value, offset, size); return imx_pcie_write_cfg(priv, bdf, offset, newval); } static int imx_pcie_dm_probe(struct udevice *dev) { |
344e04ed3 MLK-22398-1 pcie_... |
1527 |
int ret = 0; |
a11c0f44b pci: imx: Add DM ... |
1528 |
struct imx_pcie_priv *priv = dev_get_priv(dev); |
344e04ed3 MLK-22398-1 pcie_... |
1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 |
#if CONFIG_IS_ENABLED(DM_REGULATOR) ret = device_get_supply_regulator(dev, "epdev_on", &priv->epdev_on); if (ret) { priv->epdev_on = NULL; dev_dbg(dev, "no epdev_on "); } else { ret = regulator_set_enable(priv->epdev_on, true); if (ret) { dev_err(dev, "fail to enable epdev_on "); return ret; } } mdelay(100); #endif /* Enable the osc clk */ ret = gpio_request_by_name(dev, "clkreq-gpio", 0, &priv->clkreq_gpio, (GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE)); if (ret) { dev_info(dev, "%d unable to get clkreq. ", ret); } /* enable */ ret = gpio_request_by_name(dev, "disable-gpio", 0, &priv->dis_gpio, (GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE)); if (ret) { dev_info(dev, "%d unable to get disable-gpio. ", ret); } /* Set to power on */ ret = gpio_request_by_name(dev, "power-on-gpio", 0, &priv->power_on_gpio, (GPIOD_IS_OUT |GPIOD_IS_OUT_ACTIVE)); if (ret) { dev_info(dev, "%d unable to get power-on-gpio. ", ret); } /* Set to reset status */ ret = gpio_request_by_name(dev, "reset-gpio", 0, &priv->reset_gpio, (GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE)); if (ret) { dev_info(dev, "%d unable to get power-on-gpio. ", ret); } #if CONFIG_IS_ENABLED(CLK) ret = clk_get_by_name(dev, "pcie_phy", &priv->pcie_phy); if (ret) { printf("Failed to get pcie_phy clk "); return ret; } ret = clk_get_by_name(dev, "pcie_bus", &priv->pcie_bus); if (ret) { printf("Failed to get pcie_bus clk "); return ret; } ret = clk_get_by_name(dev, "pcie", &priv->pcie); if (ret) { printf("Failed to get pcie clk "); return ret; } #endif if (priv->variant == IMX8QM || priv->variant == IMX8QXP) { #if CONFIG_IS_ENABLED(CLK) ret = clk_get_by_name(dev, "pcie_per", &priv->pcie_per); if (ret) { printf("Failed to get pcie_per clk "); return ret; } ret = clk_get_by_name(dev, "pcie_inbound_axi", &priv->pcie_inbound_axi); if (ret) { printf("Failed to get pcie_inbound_axi clk "); return ret; } #endif priv->iomuxc_gpr = syscon_regmap_lookup_by_phandle(dev, "hsio"); if (IS_ERR(priv->iomuxc_gpr)) { dev_err(dev, "unable to find gpr registers "); return PTR_ERR(priv->iomuxc_gpr); } } else { #if CONFIG_IS_ENABLED(DM_REGULATOR) if (priv->variant == IMX6QP) { ret = device_get_supply_regulator(dev, "pcie-bus", &priv->pcie_bus_regulator); if (ret) { dev_dbg(dev, "no pcie_bus_regulator "); priv->pcie_bus_regulator = NULL; } } else if (priv->variant == IMX6SX) { ret = device_get_supply_regulator(dev, "pcie-phy", &priv->pcie_phy_regulator); if (ret) { dev_dbg(dev, "no pcie_phy_regulator "); priv->pcie_phy_regulator = NULL; } } #endif priv->iomuxc_gpr = syscon_regmap_lookup_by_phandle(dev, "gpr"); if (IS_ERR(priv->iomuxc_gpr)) { dev_err(dev, "unable to find gpr registers "); return PTR_ERR(priv->iomuxc_gpr); } } pci_get_regions(dev, &priv->io, &priv->mem, &priv->pref); if (priv->cpu_base) priv->cpu_addr_offset = priv->cpu_base - priv->mem->phys_start; else priv->cpu_addr_offset = 0; |
a11c0f44b pci: imx: Add DM ... |
1660 1661 1662 1663 1664 1665 |
return imx_pcie_link_up(priv); } static int imx_pcie_dm_remove(struct udevice *dev) { struct imx_pcie_priv *priv = dev_get_priv(dev); |
344e04ed3 MLK-22398-1 pcie_... |
1666 |
imx_pcie_assert_core_reset(priv, true); |
a11c0f44b pci: imx: Add DM ... |
1667 1668 1669 1670 1671 1672 1673 |
return 0; } static int imx_pcie_ofdata_to_platdata(struct udevice *dev) { struct imx_pcie_priv *priv = dev_get_priv(dev); |
344e04ed3 MLK-22398-1 pcie_... |
1674 1675 |
int ret; struct resource cfg_res; |
a11c0f44b pci: imx: Add DM ... |
1676 1677 |
priv->dbi_base = (void __iomem *)devfdt_get_addr_index(dev, 0); |
344e04ed3 MLK-22398-1 pcie_... |
1678 |
if (!priv->dbi_base) |
a11c0f44b pci: imx: Add DM ... |
1679 |
return -EINVAL; |
344e04ed3 MLK-22398-1 pcie_... |
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 |
ret = dev_read_resource_byname(dev, "config", &cfg_res); if (ret) { printf("can't get config resource(ret = %d) ", ret); return -ENOMEM; } priv->cfg_base = map_physmem(cfg_res.start, resource_size(&cfg_res), MAP_NOCACHE); priv->cfg1_base = priv->cfg_base + resource_size(&cfg_res) / 2; priv->cfg_size = resource_size(&cfg_res); priv->variant = (enum imx_pcie_variants)dev_get_driver_data(dev); if (dev_read_u32u(dev, "hsio-cfg", &priv->hsio_cfg)) priv->hsio_cfg = 0; if (dev_read_u32u(dev, "ctrl-id", &priv->ctrl_id)) priv->ctrl_id = 0; if (dev_read_u32u(dev, "ext_osc", &priv->ext_osc)) priv->ext_osc = 0; if (dev_read_u32u(dev, "cpu-base-addr", &priv->cpu_base)) priv->cpu_base = 0; if (dev_read_u32u(dev, "num-lanes", &priv->lanes)) priv->lanes = 1; debug("hsio-cfg %u, ctrl-id %u, ext_osc %u, cpu-base 0x%x ", priv->hsio_cfg, priv->ctrl_id, priv->ext_osc, priv->cpu_base); |
a11c0f44b pci: imx: Add DM ... |
1713 1714 1715 1716 1717 1718 1719 1720 1721 |
return 0; } static const struct dm_pci_ops imx_pcie_ops = { .read_config = imx_pcie_dm_read_config, .write_config = imx_pcie_dm_write_config, }; static const struct udevice_id imx_pcie_ids[] = { |
344e04ed3 MLK-22398-1 pcie_... |
1722 1723 1724 1725 1726 |
{ .compatible = "fsl,imx6q-pcie", .data = (ulong)IMX6Q, }, { .compatible = "fsl,imx6sx-pcie", .data = (ulong)IMX6SX, }, { .compatible = "fsl,imx6qp-pcie", .data = (ulong)IMX6QP, }, { .compatible = "fsl,imx8qm-pcie", .data = (ulong)IMX8QM, }, { .compatible = "fsl,imx8qxp-pcie", .data = (ulong)IMX8QXP, }, |
a11c0f44b pci: imx: Add DM ... |
1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 |
{ } }; U_BOOT_DRIVER(imx_pcie) = { .name = "imx_pcie", .id = UCLASS_PCI, .of_match = imx_pcie_ids, .ops = &imx_pcie_ops, .probe = imx_pcie_dm_probe, .remove = imx_pcie_dm_remove, .ofdata_to_platdata = imx_pcie_ofdata_to_platdata, .priv_auto_alloc_size = sizeof(struct imx_pcie_priv), .flags = DM_FLAG_OS_PREPARE, }; #endif |