| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* PCIe host controller driver for Freescale i.MX6 SoCs |
| 4 |
* |
| 5 |
* Copyright (C) 2013 Kosagi |
| 6 |
* https://www.kosagi.com |
| 7 |
* |
| 8 |
* Author: Sean Cross <[email protected]> |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <linux/bitfield.h> |
| 12 |
#include <linux/clk.h> |
| 13 |
#include <linux/delay.h> |
| 14 |
#include <linux/gpio/consumer.h> |
| 15 |
#include <linux/kernel.h> |
| 16 |
#include <linux/mfd/syscon.h> |
| 17 |
#include <linux/mfd/syscon/imx6q-iomuxc-gpr.h> |
| 18 |
#include <linux/mfd/syscon/imx7-iomuxc-gpr.h> |
| 19 |
#include <linux/module.h> |
| 20 |
#include <linux/of.h> |
| 21 |
#include <linux/of_address.h> |
| 22 |
#include <linux/pci.h> |
| 23 |
#include <linux/platform_device.h> |
| 24 |
#include <linux/regmap.h> |
| 25 |
#include <linux/regulator/consumer.h> |
| 26 |
#include <linux/resource.h> |
| 27 |
#include <linux/signal.h> |
| 28 |
#include <linux/types.h> |
| 29 |
#include <linux/interrupt.h> |
| 30 |
#include <linux/reset.h> |
| 31 |
#include <linux/phy/pcie.h> |
| 32 |
#include <linux/phy/phy.h> |
| 33 |
#include <linux/pm_domain.h> |
| 34 |
#include <linux/pm_runtime.h> |
| 35 |
|
| 36 |
#include "../../pci.h" |
| 37 |
#include "pcie-designware.h" |
| 38 |
|
| 39 |
#define IMX8MQ_GPR_PCIE_REF_USE_PAD BIT(9) |
| 40 |
#define IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN BIT(10) |
| 41 |
#define IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE BIT(11) |
| 42 |
#define IMX8MQ_GPR_PCIE_VREG_BYPASS BIT(12) |
| 43 |
#define IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE GENMASK(11, 8) |
| 44 |
|
| 45 |
#define IMX95_PCIE_PHY_GEN_CTRL 0x0 |
| 46 |
#define IMX95_PCIE_REF_USE_PAD BIT(17) |
| 47 |
|
| 48 |
#define IMX95_PCIE_PHY_MPLLA_CTRL 0x10 |
| 49 |
#define IMX95_PCIE_PHY_MPLL_STATE BIT(30) |
| 50 |
|
| 51 |
#define IMX95_PCIE_SS_RW_REG_0 0xf0 |
| 52 |
#define IMX95_PCIE_REF_CLKEN BIT(23) |
| 53 |
#define IMX95_PCIE_PHY_CR_PARA_SEL BIT(9) |
| 54 |
#define IMX95_PCIE_SS_RW_REG_1 0xf4 |
| 55 |
#define IMX95_PCIE_CLKREQ_OVERRIDE_EN BIT(8) |
| 56 |
#define IMX95_PCIE_CLKREQ_OVERRIDE_VAL BIT(9) |
| 57 |
#define IMX95_PCIE_SYS_AUX_PWR_DET BIT(31) |
| 58 |
|
| 59 |
#define IMX95_PE0_GEN_CTRL_1 0x1050 |
| 60 |
#define IMX95_PCIE_DEVICE_TYPE GENMASK(3, 0) |
| 61 |
|
| 62 |
#define IMX95_PE0_GEN_CTRL_3 0x1058 |
| 63 |
#define IMX95_PCIE_LTSSM_EN BIT(0) |
| 64 |
|
| 65 |
#define IMX95_PE0_LUT_ACSCTRL 0x1008 |
| 66 |
#define IMX95_PEO_LUT_RWA BIT(16) |
| 67 |
#define IMX95_PE0_LUT_ENLOC GENMASK(4, 0) |
| 68 |
|
| 69 |
#define IMX95_PE0_LUT_DATA1 0x100c |
| 70 |
#define IMX95_PE0_LUT_VLD BIT(31) |
| 71 |
#define IMX95_PE0_LUT_DAC_ID GENMASK(10, 8) |
| 72 |
#define IMX95_PE0_LUT_STREAM_ID GENMASK(5, 0) |
| 73 |
|
| 74 |
#define IMX95_PE0_LUT_DATA2 0x1010 |
| 75 |
#define IMX95_PE0_LUT_REQID GENMASK(31, 16) |
| 76 |
#define IMX95_PE0_LUT_MASK GENMASK(15, 0) |
| 77 |
|
| 78 |
#define IMX95_SID_MASK GENMASK(5, 0) |
| 79 |
#define IMX95_MAX_LUT 32 |
| 80 |
|
| 81 |
#define IMX95_PCIE_RST_CTRL 0x3010 |
| 82 |
#define IMX95_PCIE_COLD_RST BIT(0) |
| 83 |
|
| 84 |
#define to_imx_pcie(x) dev_get_drvdata((x)->dev) |
| 85 |
|
| 86 |
enum imx_pcie_variants { |
| 87 |
IMX6Q, |
| 88 |
IMX6SX, |
| 89 |
IMX6QP, |
| 90 |
IMX7D, |
| 91 |
IMX8MQ, |
| 92 |
IMX8MM, |
| 93 |
IMX8MP, |
| 94 |
IMX8Q, |
| 95 |
IMX95, |
| 96 |
IMX8MQ_EP, |
| 97 |
IMX8MM_EP, |
| 98 |
IMX8MP_EP, |
| 99 |
IMX8Q_EP, |
| 100 |
IMX95_EP, |
| 101 |
}; |
| 102 |
|
| 103 |
#define IMX_PCIE_FLAG_IMX_PHY BIT(0) |
| 104 |
#define IMX_PCIE_FLAG_SPEED_CHANGE_WORKAROUND BIT(1) |
| 105 |
#define IMX_PCIE_FLAG_SUPPORTS_SUSPEND BIT(2) |
| 106 |
#define IMX_PCIE_FLAG_HAS_PHYDRV BIT(3) |
| 107 |
#define IMX_PCIE_FLAG_HAS_APP_RESET BIT(4) |
| 108 |
#define IMX_PCIE_FLAG_HAS_PHY_RESET BIT(5) |
| 109 |
#define IMX_PCIE_FLAG_HAS_SERDES BIT(6) |
| 110 |
#define IMX_PCIE_FLAG_SUPPORT_64BIT BIT(7) |
| 111 |
#define IMX_PCIE_FLAG_CPU_ADDR_FIXUP BIT(8) |
| 112 |
/* |
| 113 |
* Because of ERR005723 (PCIe does not support L2 power down) we need to |
| 114 |
* workaround suspend resume on some devices which are affected by this errata. |
| 115 |
*/ |
| 116 |
#define IMX_PCIE_FLAG_BROKEN_SUSPEND BIT(9) |
| 117 |
#define IMX_PCIE_FLAG_HAS_LUT BIT(10) |
| 118 |
#define IMX_PCIE_FLAG_8GT_ECN_ERR051586 BIT(11) |
| 119 |
#define IMX_PCIE_FLAG_SKIP_L23_READY BIT(12) |
| 120 |
/* Preserve MSI capability for platforms that require it */ |
| 121 |
#define IMX_PCIE_FLAG_KEEP_MSI_CAP BIT(13) |
| 122 |
|
| 123 |
#define imx_check_flag(pci, val) (pci->drvdata->flags & val) |
| 124 |
|
| 125 |
#define IMX_PCIE_MAX_INSTANCES 2 |
| 126 |
|
| 127 |
struct imx_pcie; |
| 128 |
|
| 129 |
struct imx_pcie_drvdata { |
| 130 |
enum imx_pcie_variants variant; |
| 131 |
enum dw_pcie_device_mode mode; |
| 132 |
u32 flags; |
| 133 |
int dbi_length; |
| 134 |
const char *gpr; |
| 135 |
const u32 ltssm_off; |
| 136 |
const u32 ltssm_mask; |
| 137 |
const u32 mode_off[IMX_PCIE_MAX_INSTANCES]; |
| 138 |
const u32 mode_mask[IMX_PCIE_MAX_INSTANCES]; |
| 139 |
const struct pci_epc_features *epc_features; |
| 140 |
int (*init_phy)(struct imx_pcie *pcie); |
| 141 |
int (*enable_ref_clk)(struct imx_pcie *pcie, bool enable); |
| 142 |
int (*core_reset)(struct imx_pcie *pcie, bool assert); |
| 143 |
int (*wait_pll_lock)(struct imx_pcie *pcie); |
| 144 |
void (*clr_clkreq_override)(struct imx_pcie *pcie); |
| 145 |
const struct dw_pcie_host_ops *ops; |
| 146 |
}; |
| 147 |
|
| 148 |
struct imx_lut_data { |
| 149 |
u32 data1; |
| 150 |
u32 data2; |
| 151 |
}; |
| 152 |
|
| 153 |
struct imx_pcie { |
| 154 |
struct dw_pcie *pci; |
| 155 |
struct gpio_desc *reset_gpiod; |
| 156 |
struct clk_bulk_data *clks; |
| 157 |
int num_clks; |
| 158 |
bool supports_clkreq; |
| 159 |
bool enable_ext_refclk; |
| 160 |
struct regmap *iomuxc_gpr; |
| 161 |
u16 msi_ctrl; |
| 162 |
u32 controller_id; |
| 163 |
struct reset_control *pciephy_reset; |
| 164 |
struct reset_control *apps_reset; |
| 165 |
u32 tx_deemph_gen1; |
| 166 |
u32 tx_deemph_gen2_3p5db; |
| 167 |
u32 tx_deemph_gen2_6db; |
| 168 |
u32 tx_swing_full; |
| 169 |
u32 tx_swing_low; |
| 170 |
struct regulator *vpcie; |
| 171 |
struct regulator *vph; |
| 172 |
void __iomem *phy_base; |
| 173 |
|
| 174 |
/* LUT data for pcie */ |
| 175 |
struct imx_lut_data luts[IMX95_MAX_LUT]; |
| 176 |
/* power domain for pcie */ |
| 177 |
struct device *pd_pcie; |
| 178 |
/* power domain for pcie phy */ |
| 179 |
struct device *pd_pcie_phy; |
| 180 |
struct phy *phy; |
| 181 |
const struct imx_pcie_drvdata *drvdata; |
| 182 |
|
| 183 |
/* Ensure that only one device's LUT is configured at any given time */ |
| 184 |
struct mutex lock; |
| 185 |
}; |
| 186 |
|
| 187 |
/* Parameters for the waiting for PCIe PHY PLL to lock on i.MX7 */ |
| 188 |
#define PHY_PLL_LOCK_WAIT_USLEEP_MAX 200 |
| 189 |
#define PHY_PLL_LOCK_WAIT_TIMEOUT (2000 * PHY_PLL_LOCK_WAIT_USLEEP_MAX) |
| 190 |
|
| 191 |
/* PCIe Port Logic registers (memory-mapped) */ |
| 192 |
#define PL_OFFSET 0x700 |
| 193 |
|
| 194 |
#define PCIE_PHY_CTRL (PL_OFFSET + 0x114) |
| 195 |
#define PCIE_PHY_CTRL_DATA(x) FIELD_PREP(GENMASK(15, 0), (x)) |
| 196 |
#define PCIE_PHY_CTRL_CAP_ADR BIT(16) |
| 197 |
#define PCIE_PHY_CTRL_CAP_DAT BIT(17) |
| 198 |
#define PCIE_PHY_CTRL_WR BIT(18) |
| 199 |
#define PCIE_PHY_CTRL_RD BIT(19) |
| 200 |
|
| 201 |
#define PCIE_PHY_STAT (PL_OFFSET + 0x110) |
| 202 |
#define PCIE_PHY_STAT_ACK BIT(16) |
| 203 |
|
| 204 |
/* PHY registers (not memory-mapped) */ |
| 205 |
#define PCIE_PHY_ATEOVRD 0x10 |
| 206 |
#define PCIE_PHY_ATEOVRD_EN BIT(2) |
| 207 |
#define PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT 0 |
| 208 |
#define PCIE_PHY_ATEOVRD_REF_CLKDIV_MASK 0x1 |
| 209 |
|
| 210 |
#define PCIE_PHY_MPLL_OVRD_IN_LO 0x11 |
| 211 |
#define PCIE_PHY_MPLL_MULTIPLIER_SHIFT 2 |
| 212 |
#define PCIE_PHY_MPLL_MULTIPLIER_MASK 0x7f |
| 213 |
#define PCIE_PHY_MPLL_MULTIPLIER_OVRD BIT(9) |
| 214 |
|
| 215 |
#define PCIE_PHY_RX_ASIC_OUT 0x100D |
| 216 |
#define PCIE_PHY_RX_ASIC_OUT_VALID (1 << 0) |
| 217 |
|
| 218 |
/* iMX7 PCIe PHY registers */ |
| 219 |
#define PCIE_PHY_CMN_REG4 0x14 |
| 220 |
/* These are probably the bits that *aren't* DCC_FB_EN */ |
| 221 |
#define PCIE_PHY_CMN_REG4_DCC_FB_EN 0x29 |
| 222 |
|
| 223 |
#define PCIE_PHY_CMN_REG15 0x54 |
| 224 |
#define PCIE_PHY_CMN_REG15_DLY_4 BIT(2) |
| 225 |
#define PCIE_PHY_CMN_REG15_PLL_PD BIT(5) |
| 226 |
#define PCIE_PHY_CMN_REG15_OVRD_PLL_PD BIT(7) |
| 227 |
|
| 228 |
#define PCIE_PHY_CMN_REG24 0x90 |
| 229 |
#define PCIE_PHY_CMN_REG24_RX_EQ BIT(6) |
| 230 |
#define PCIE_PHY_CMN_REG24_RX_EQ_SEL BIT(3) |
| 231 |
|
| 232 |
#define PCIE_PHY_CMN_REG26 0x98 |
| 233 |
#define PCIE_PHY_CMN_REG26_ATT_MODE 0xBC |
| 234 |
|
| 235 |
#define PHY_RX_OVRD_IN_LO 0x1005 |
| 236 |
#define PHY_RX_OVRD_IN_LO_RX_DATA_EN BIT(5) |
| 237 |
#define PHY_RX_OVRD_IN_LO_RX_PLL_EN BIT(3) |
| 238 |
|
| 239 |
static unsigned int imx_pcie_grp_offset(const struct imx_pcie *imx_pcie) |
| 240 |
{ |
| 241 |
WARN_ON(imx_pcie->drvdata->variant != IMX8MQ && |
| 242 |
imx_pcie->drvdata->variant != IMX8MQ_EP && |
| 243 |
imx_pcie->drvdata->variant != IMX8MM && |
| 244 |
imx_pcie->drvdata->variant != IMX8MM_EP && |
| 245 |
imx_pcie->drvdata->variant != IMX8MP && |
| 246 |
imx_pcie->drvdata->variant != IMX8MP_EP); |
| 247 |
return imx_pcie->controller_id == 1 ? IOMUXC_GPR16 : IOMUXC_GPR14; |
| 248 |
} |
| 249 |
|
| 250 |
static int imx95_pcie_init_phy(struct imx_pcie *imx_pcie) |
| 251 |
{ |
| 252 |
bool ext = imx_pcie->enable_ext_refclk; |
| 253 |
|
| 254 |
/* |
| 255 |
* ERR051624: The Controller Without Vaux Cannot Exit L23 Ready |
| 256 |
* Through Beacon or PERST# De-assertion |
| 257 |
* |
| 258 |
* When the auxiliary power is not available, the controller |
| 259 |
* cannot exit from L23 Ready with beacon or PERST# de-assertion |
| 260 |
* when main power is not removed. |
| 261 |
* |
| 262 |
* Workaround: Set SS_RW_REG_1[SYS_AUX_PWR_DET] to 1. |
| 263 |
*/ |
| 264 |
regmap_set_bits(imx_pcie->iomuxc_gpr, IMX95_PCIE_SS_RW_REG_1, |
| 265 |
IMX95_PCIE_SYS_AUX_PWR_DET); |
| 266 |
|
| 267 |
regmap_update_bits(imx_pcie->iomuxc_gpr, |
| 268 |
IMX95_PCIE_SS_RW_REG_0, |
| 269 |
IMX95_PCIE_PHY_CR_PARA_SEL, |
| 270 |
IMX95_PCIE_PHY_CR_PARA_SEL); |
| 271 |
|
| 272 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IMX95_PCIE_PHY_GEN_CTRL, |
| 273 |
IMX95_PCIE_REF_USE_PAD, |
| 274 |
ext ? IMX95_PCIE_REF_USE_PAD : 0); |
| 275 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IMX95_PCIE_SS_RW_REG_0, |
| 276 |
IMX95_PCIE_REF_CLKEN, |
| 277 |
ext ? 0 : IMX95_PCIE_REF_CLKEN); |
| 278 |
|
| 279 |
return 0; |
| 280 |
} |
| 281 |
|
| 282 |
static void imx_pcie_configure_type(struct imx_pcie *imx_pcie) |
| 283 |
{ |
| 284 |
const struct imx_pcie_drvdata *drvdata = imx_pcie->drvdata; |
| 285 |
unsigned int mask, val, mode, id; |
| 286 |
|
| 287 |
if (drvdata->mode == DW_PCIE_EP_TYPE) |
| 288 |
mode = PCI_EXP_TYPE_ENDPOINT; |
| 289 |
else |
| 290 |
mode = PCI_EXP_TYPE_ROOT_PORT; |
| 291 |
|
| 292 |
id = imx_pcie->controller_id; |
| 293 |
|
| 294 |
/* If mode_mask is 0, generic PHY driver is used to set the mode */ |
| 295 |
if (!drvdata->mode_mask[0]) |
| 296 |
return; |
| 297 |
|
| 298 |
/* If mode_mask[id] is 0, each controller has its individual GPR */ |
| 299 |
if (!drvdata->mode_mask[id]) |
| 300 |
id = 0; |
| 301 |
|
| 302 |
mask = drvdata->mode_mask[id]; |
| 303 |
val = mode << (ffs(mask) - 1); |
| 304 |
|
| 305 |
regmap_update_bits(imx_pcie->iomuxc_gpr, drvdata->mode_off[id], mask, val); |
| 306 |
} |
| 307 |
|
| 308 |
static int pcie_phy_poll_ack(struct imx_pcie *imx_pcie, bool exp_val) |
| 309 |
{ |
| 310 |
struct dw_pcie *pci = imx_pcie->pci; |
| 311 |
bool val; |
| 312 |
u32 max_iterations = 10; |
| 313 |
u32 wait_counter = 0; |
| 314 |
|
| 315 |
do { |
| 316 |
val = dw_pcie_readl_dbi(pci, PCIE_PHY_STAT) & |
| 317 |
PCIE_PHY_STAT_ACK; |
| 318 |
wait_counter++; |
| 319 |
|
| 320 |
if (val == exp_val) |
| 321 |
return 0; |
| 322 |
|
| 323 |
udelay(1); |
| 324 |
} while (wait_counter < max_iterations); |
| 325 |
|
| 326 |
return -ETIMEDOUT; |
| 327 |
} |
| 328 |
|
| 329 |
static int pcie_phy_wait_ack(struct imx_pcie *imx_pcie, int addr) |
| 330 |
{ |
| 331 |
struct dw_pcie *pci = imx_pcie->pci; |
| 332 |
u32 val; |
| 333 |
int ret; |
| 334 |
|
| 335 |
val = PCIE_PHY_CTRL_DATA(addr); |
| 336 |
dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val); |
| 337 |
|
| 338 |
val |= PCIE_PHY_CTRL_CAP_ADR; |
| 339 |
dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val); |
| 340 |
|
| 341 |
ret = pcie_phy_poll_ack(imx_pcie, true); |
| 342 |
if (ret) |
| 343 |
return ret; |
| 344 |
|
| 345 |
val = PCIE_PHY_CTRL_DATA(addr); |
| 346 |
dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val); |
| 347 |
|
| 348 |
return pcie_phy_poll_ack(imx_pcie, false); |
| 349 |
} |
| 350 |
|
| 351 |
/* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */ |
| 352 |
static int pcie_phy_read(struct imx_pcie *imx_pcie, int addr, u16 *data) |
| 353 |
{ |
| 354 |
struct dw_pcie *pci = imx_pcie->pci; |
| 355 |
u32 phy_ctl; |
| 356 |
int ret; |
| 357 |
|
| 358 |
ret = pcie_phy_wait_ack(imx_pcie, addr); |
| 359 |
if (ret) |
| 360 |
return ret; |
| 361 |
|
| 362 |
/* assert Read signal */ |
| 363 |
phy_ctl = PCIE_PHY_CTRL_RD; |
| 364 |
dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, phy_ctl); |
| 365 |
|
| 366 |
ret = pcie_phy_poll_ack(imx_pcie, true); |
| 367 |
if (ret) |
| 368 |
return ret; |
| 369 |
|
| 370 |
*data = dw_pcie_readl_dbi(pci, PCIE_PHY_STAT); |
| 371 |
|
| 372 |
/* deassert Read signal */ |
| 373 |
dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, 0x00); |
| 374 |
|
| 375 |
return pcie_phy_poll_ack(imx_pcie, false); |
| 376 |
} |
| 377 |
|
| 378 |
static int pcie_phy_write(struct imx_pcie *imx_pcie, int addr, u16 data) |
| 379 |
{ |
| 380 |
struct dw_pcie *pci = imx_pcie->pci; |
| 381 |
u32 var; |
| 382 |
int ret; |
| 383 |
|
| 384 |
/* write addr */ |
| 385 |
/* cap addr */ |
| 386 |
ret = pcie_phy_wait_ack(imx_pcie, addr); |
| 387 |
if (ret) |
| 388 |
return ret; |
| 389 |
|
| 390 |
var = PCIE_PHY_CTRL_DATA(data); |
| 391 |
dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
| 392 |
|
| 393 |
/* capture data */ |
| 394 |
var |= PCIE_PHY_CTRL_CAP_DAT; |
| 395 |
dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
| 396 |
|
| 397 |
ret = pcie_phy_poll_ack(imx_pcie, true); |
| 398 |
if (ret) |
| 399 |
return ret; |
| 400 |
|
| 401 |
/* deassert cap data */ |
| 402 |
var = PCIE_PHY_CTRL_DATA(data); |
| 403 |
dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
| 404 |
|
| 405 |
/* wait for ack de-assertion */ |
| 406 |
ret = pcie_phy_poll_ack(imx_pcie, false); |
| 407 |
if (ret) |
| 408 |
return ret; |
| 409 |
|
| 410 |
/* assert wr signal */ |
| 411 |
var = PCIE_PHY_CTRL_WR; |
| 412 |
dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
| 413 |
|
| 414 |
/* wait for ack */ |
| 415 |
ret = pcie_phy_poll_ack(imx_pcie, true); |
| 416 |
if (ret) |
| 417 |
return ret; |
| 418 |
|
| 419 |
/* deassert wr signal */ |
| 420 |
var = PCIE_PHY_CTRL_DATA(data); |
| 421 |
dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
| 422 |
|
| 423 |
/* wait for ack de-assertion */ |
| 424 |
ret = pcie_phy_poll_ack(imx_pcie, false); |
| 425 |
if (ret) |
| 426 |
return ret; |
| 427 |
|
| 428 |
dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, 0x0); |
| 429 |
|
| 430 |
return 0; |
| 431 |
} |
| 432 |
|
| 433 |
static int imx8mq_pcie_init_phy(struct imx_pcie *imx_pcie) |
| 434 |
{ |
| 435 |
/* TODO: This code assumes external oscillator is being used */ |
| 436 |
regmap_update_bits(imx_pcie->iomuxc_gpr, |
| 437 |
imx_pcie_grp_offset(imx_pcie), |
| 438 |
IMX8MQ_GPR_PCIE_REF_USE_PAD, |
| 439 |
IMX8MQ_GPR_PCIE_REF_USE_PAD); |
| 440 |
/* |
| 441 |
* Per the datasheet, the PCIE_VPH is suggested to be 1.8V. If the |
| 442 |
* PCIE_VPH is supplied by 3.3V, the VREG_BYPASS should be cleared |
| 443 |
* to zero. |
| 444 |
*/ |
| 445 |
if (imx_pcie->vph && regulator_get_voltage(imx_pcie->vph) > 3000000) |
| 446 |
regmap_update_bits(imx_pcie->iomuxc_gpr, |
| 447 |
imx_pcie_grp_offset(imx_pcie), |
| 448 |
IMX8MQ_GPR_PCIE_VREG_BYPASS, |
| 449 |
0); |
| 450 |
|
| 451 |
return 0; |
| 452 |
} |
| 453 |
|
| 454 |
static int imx_pcie_init_phy(struct imx_pcie *imx_pcie) |
| 455 |
{ |
| 456 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 457 |
IMX6Q_GPR12_PCIE_CTL_2, 0 << 10); |
| 458 |
|
| 459 |
/* configure constant input signal to the pcie ctrl and phy */ |
| 460 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 461 |
IMX6Q_GPR12_LOS_LEVEL, 9 << 4); |
| 462 |
|
| 463 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR8, |
| 464 |
IMX6Q_GPR8_TX_DEEMPH_GEN1, |
| 465 |
imx_pcie->tx_deemph_gen1 << 0); |
| 466 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR8, |
| 467 |
IMX6Q_GPR8_TX_DEEMPH_GEN2_3P5DB, |
| 468 |
imx_pcie->tx_deemph_gen2_3p5db << 6); |
| 469 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR8, |
| 470 |
IMX6Q_GPR8_TX_DEEMPH_GEN2_6DB, |
| 471 |
imx_pcie->tx_deemph_gen2_6db << 12); |
| 472 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR8, |
| 473 |
IMX6Q_GPR8_TX_SWING_FULL, |
| 474 |
imx_pcie->tx_swing_full << 18); |
| 475 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR8, |
| 476 |
IMX6Q_GPR8_TX_SWING_LOW, |
| 477 |
imx_pcie->tx_swing_low << 25); |
| 478 |
return 0; |
| 479 |
} |
| 480 |
|
| 481 |
static int imx6sx_pcie_init_phy(struct imx_pcie *imx_pcie) |
| 482 |
{ |
| 483 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 484 |
IMX6SX_GPR12_PCIE_RX_EQ_MASK, IMX6SX_GPR12_PCIE_RX_EQ_2); |
| 485 |
|
| 486 |
return imx_pcie_init_phy(imx_pcie); |
| 487 |
} |
| 488 |
|
| 489 |
static void imx7d_pcie_wait_for_phy_pll_lock(struct imx_pcie *imx_pcie) |
| 490 |
{ |
| 491 |
u32 val; |
| 492 |
struct device *dev = imx_pcie->pci->dev; |
| 493 |
|
| 494 |
if (regmap_read_poll_timeout(imx_pcie->iomuxc_gpr, |
| 495 |
IOMUXC_GPR22, val, |
| 496 |
val & IMX7D_GPR22_PCIE_PHY_PLL_LOCKED, |
| 497 |
PHY_PLL_LOCK_WAIT_USLEEP_MAX, |
| 498 |
PHY_PLL_LOCK_WAIT_TIMEOUT)) |
| 499 |
dev_err(dev, "PCIe PLL lock timeout\n"); |
| 500 |
} |
| 501 |
|
| 502 |
static int imx95_pcie_wait_for_phy_pll_lock(struct imx_pcie *imx_pcie) |
| 503 |
{ |
| 504 |
u32 val; |
| 505 |
struct device *dev = imx_pcie->pci->dev; |
| 506 |
|
| 507 |
if (regmap_read_poll_timeout(imx_pcie->iomuxc_gpr, |
| 508 |
IMX95_PCIE_PHY_MPLLA_CTRL, val, |
| 509 |
val & IMX95_PCIE_PHY_MPLL_STATE, |
| 510 |
PHY_PLL_LOCK_WAIT_USLEEP_MAX, |
| 511 |
PHY_PLL_LOCK_WAIT_TIMEOUT)) { |
| 512 |
dev_err(dev, "PCIe PLL lock timeout\n"); |
| 513 |
return -ETIMEDOUT; |
| 514 |
} |
| 515 |
|
| 516 |
return 0; |
| 517 |
} |
| 518 |
|
| 519 |
static int imx_setup_phy_mpll(struct imx_pcie *imx_pcie) |
| 520 |
{ |
| 521 |
unsigned long phy_rate = 0; |
| 522 |
int mult, div; |
| 523 |
u16 val; |
| 524 |
int i; |
| 525 |
struct clk_bulk_data *clks = imx_pcie->clks; |
| 526 |
|
| 527 |
if (!(imx_pcie->drvdata->flags & IMX_PCIE_FLAG_IMX_PHY)) |
| 528 |
return 0; |
| 529 |
|
| 530 |
for (i = 0; i < imx_pcie->num_clks; i++) |
| 531 |
if (strncmp(clks[i].id, "pcie_phy", 8) == 0) |
| 532 |
phy_rate = clk_get_rate(clks[i].clk); |
| 533 |
|
| 534 |
switch (phy_rate) { |
| 535 |
case 125000000: |
| 536 |
/* |
| 537 |
* The default settings of the MPLL are for a 125MHz input |
| 538 |
* clock, so no need to reconfigure anything in that case. |
| 539 |
*/ |
| 540 |
return 0; |
| 541 |
case 100000000: |
| 542 |
mult = 25; |
| 543 |
div = 0; |
| 544 |
break; |
| 545 |
case 200000000: |
| 546 |
mult = 25; |
| 547 |
div = 1; |
| 548 |
break; |
| 549 |
default: |
| 550 |
dev_err(imx_pcie->pci->dev, |
| 551 |
"Unsupported PHY reference clock rate %lu\n", phy_rate); |
| 552 |
return -EINVAL; |
| 553 |
} |
| 554 |
|
| 555 |
pcie_phy_read(imx_pcie, PCIE_PHY_MPLL_OVRD_IN_LO, &val); |
| 556 |
val &= ~(PCIE_PHY_MPLL_MULTIPLIER_MASK << |
| 557 |
PCIE_PHY_MPLL_MULTIPLIER_SHIFT); |
| 558 |
val |= mult << PCIE_PHY_MPLL_MULTIPLIER_SHIFT; |
| 559 |
val |= PCIE_PHY_MPLL_MULTIPLIER_OVRD; |
| 560 |
pcie_phy_write(imx_pcie, PCIE_PHY_MPLL_OVRD_IN_LO, val); |
| 561 |
|
| 562 |
pcie_phy_read(imx_pcie, PCIE_PHY_ATEOVRD, &val); |
| 563 |
val &= ~(PCIE_PHY_ATEOVRD_REF_CLKDIV_MASK << |
| 564 |
PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT); |
| 565 |
val |= div << PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT; |
| 566 |
val |= PCIE_PHY_ATEOVRD_EN; |
| 567 |
pcie_phy_write(imx_pcie, PCIE_PHY_ATEOVRD, val); |
| 568 |
|
| 569 |
return 0; |
| 570 |
} |
| 571 |
|
| 572 |
static void imx_pcie_reset_phy(struct imx_pcie *imx_pcie) |
| 573 |
{ |
| 574 |
u16 tmp; |
| 575 |
|
| 576 |
if (!(imx_pcie->drvdata->flags & IMX_PCIE_FLAG_IMX_PHY)) |
| 577 |
return; |
| 578 |
|
| 579 |
pcie_phy_read(imx_pcie, PHY_RX_OVRD_IN_LO, &tmp); |
| 580 |
tmp |= (PHY_RX_OVRD_IN_LO_RX_DATA_EN | |
| 581 |
PHY_RX_OVRD_IN_LO_RX_PLL_EN); |
| 582 |
pcie_phy_write(imx_pcie, PHY_RX_OVRD_IN_LO, tmp); |
| 583 |
|
| 584 |
usleep_range(2000, 3000); |
| 585 |
|
| 586 |
pcie_phy_read(imx_pcie, PHY_RX_OVRD_IN_LO, &tmp); |
| 587 |
tmp &= ~(PHY_RX_OVRD_IN_LO_RX_DATA_EN | |
| 588 |
PHY_RX_OVRD_IN_LO_RX_PLL_EN); |
| 589 |
pcie_phy_write(imx_pcie, PHY_RX_OVRD_IN_LO, tmp); |
| 590 |
} |
| 591 |
|
| 592 |
#ifdef CONFIG_ARM |
| 593 |
/* Added for PCI abort handling */ |
| 594 |
static int imx6q_pcie_abort_handler(unsigned long addr, |
| 595 |
unsigned int fsr, struct pt_regs *regs) |
| 596 |
{ |
| 597 |
unsigned long pc = instruction_pointer(regs); |
| 598 |
unsigned long instr = *(unsigned long *)pc; |
| 599 |
int reg = (instr >> 12) & 15; |
| 600 |
|
| 601 |
/* |
| 602 |
* If the instruction being executed was a read, |
| 603 |
* make it look like it read all-ones. |
| 604 |
*/ |
| 605 |
if ((instr & 0x0c100000) == 0x04100000) { |
| 606 |
unsigned long val; |
| 607 |
|
| 608 |
if (instr & 0x00400000) |
| 609 |
val = 255; |
| 610 |
else |
| 611 |
val = -1; |
| 612 |
|
| 613 |
regs->uregs[reg] = val; |
| 614 |
regs->ARM_pc += 4; |
| 615 |
return 0; |
| 616 |
} |
| 617 |
|
| 618 |
if ((instr & 0x0e100090) == 0x00100090) { |
| 619 |
regs->uregs[reg] = -1; |
| 620 |
regs->ARM_pc += 4; |
| 621 |
return 0; |
| 622 |
} |
| 623 |
|
| 624 |
return 1; |
| 625 |
} |
| 626 |
#endif |
| 627 |
|
| 628 |
static int imx_pcie_attach_pd(struct device *dev) |
| 629 |
{ |
| 630 |
struct imx_pcie *imx_pcie = dev_get_drvdata(dev); |
| 631 |
struct device_link *link; |
| 632 |
|
| 633 |
/* Do nothing when in a single power domain */ |
| 634 |
if (dev->pm_domain) |
| 635 |
return 0; |
| 636 |
|
| 637 |
imx_pcie->pd_pcie = dev_pm_domain_attach_by_name(dev, "pcie"); |
| 638 |
if (IS_ERR(imx_pcie->pd_pcie)) |
| 639 |
return PTR_ERR(imx_pcie->pd_pcie); |
| 640 |
/* Do nothing when power domain missing */ |
| 641 |
if (!imx_pcie->pd_pcie) |
| 642 |
return 0; |
| 643 |
link = device_link_add(dev, imx_pcie->pd_pcie, |
| 644 |
DL_FLAG_STATELESS | |
| 645 |
DL_FLAG_PM_RUNTIME | |
| 646 |
DL_FLAG_RPM_ACTIVE); |
| 647 |
if (!link) { |
| 648 |
dev_err(dev, "Failed to add device_link to pcie pd\n"); |
| 649 |
return -EINVAL; |
| 650 |
} |
| 651 |
|
| 652 |
imx_pcie->pd_pcie_phy = dev_pm_domain_attach_by_name(dev, "pcie_phy"); |
| 653 |
if (IS_ERR(imx_pcie->pd_pcie_phy)) |
| 654 |
return PTR_ERR(imx_pcie->pd_pcie_phy); |
| 655 |
|
| 656 |
link = device_link_add(dev, imx_pcie->pd_pcie_phy, |
| 657 |
DL_FLAG_STATELESS | |
| 658 |
DL_FLAG_PM_RUNTIME | |
| 659 |
DL_FLAG_RPM_ACTIVE); |
| 660 |
if (!link) { |
| 661 |
dev_err(dev, "Failed to add device_link to pcie_phy pd\n"); |
| 662 |
return -EINVAL; |
| 663 |
} |
| 664 |
|
| 665 |
return 0; |
| 666 |
} |
| 667 |
|
| 668 |
static int imx6sx_pcie_enable_ref_clk(struct imx_pcie *imx_pcie, bool enable) |
| 669 |
{ |
| 670 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 671 |
IMX6SX_GPR12_PCIE_TEST_POWERDOWN, |
| 672 |
enable ? 0 : IMX6SX_GPR12_PCIE_TEST_POWERDOWN); |
| 673 |
return 0; |
| 674 |
} |
| 675 |
|
| 676 |
static int imx6q_pcie_enable_ref_clk(struct imx_pcie *imx_pcie, bool enable) |
| 677 |
{ |
| 678 |
if (enable) { |
| 679 |
/* power up core phy and enable ref clock */ |
| 680 |
regmap_clear_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_TEST_PD); |
| 681 |
/* |
| 682 |
* The async reset input need ref clock to sync internally, |
| 683 |
* when the ref clock comes after reset, internal synced |
| 684 |
* reset time is too short, cannot meet the requirement. |
| 685 |
* Add a ~10us delay here. |
| 686 |
*/ |
| 687 |
usleep_range(10, 100); |
| 688 |
regmap_set_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_REF_CLK_EN); |
| 689 |
} else { |
| 690 |
regmap_clear_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_REF_CLK_EN); |
| 691 |
regmap_set_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_TEST_PD); |
| 692 |
} |
| 693 |
|
| 694 |
return 0; |
| 695 |
} |
| 696 |
|
| 697 |
static void imx8mm_pcie_clkreq_override(struct imx_pcie *imx_pcie, bool enable) |
| 698 |
{ |
| 699 |
int offset = imx_pcie_grp_offset(imx_pcie); |
| 700 |
|
| 701 |
regmap_update_bits(imx_pcie->iomuxc_gpr, offset, |
| 702 |
IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE, |
| 703 |
enable ? 0 : IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE); |
| 704 |
regmap_update_bits(imx_pcie->iomuxc_gpr, offset, |
| 705 |
IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN, |
| 706 |
enable ? IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN : 0); |
| 707 |
} |
| 708 |
|
| 709 |
static int imx8mm_pcie_enable_ref_clk(struct imx_pcie *imx_pcie, bool enable) |
| 710 |
{ |
| 711 |
imx8mm_pcie_clkreq_override(imx_pcie, enable); |
| 712 |
return 0; |
| 713 |
} |
| 714 |
|
| 715 |
static int imx7d_pcie_enable_ref_clk(struct imx_pcie *imx_pcie, bool enable) |
| 716 |
{ |
| 717 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 718 |
IMX7D_GPR12_PCIE_PHY_REFCLK_SEL, |
| 719 |
enable ? 0 : IMX7D_GPR12_PCIE_PHY_REFCLK_SEL); |
| 720 |
return 0; |
| 721 |
} |
| 722 |
|
| 723 |
static void imx95_pcie_clkreq_override(struct imx_pcie *imx_pcie, bool enable) |
| 724 |
{ |
| 725 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IMX95_PCIE_SS_RW_REG_1, |
| 726 |
IMX95_PCIE_CLKREQ_OVERRIDE_EN, |
| 727 |
enable ? IMX95_PCIE_CLKREQ_OVERRIDE_EN : 0); |
| 728 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IMX95_PCIE_SS_RW_REG_1, |
| 729 |
IMX95_PCIE_CLKREQ_OVERRIDE_VAL, |
| 730 |
enable ? IMX95_PCIE_CLKREQ_OVERRIDE_VAL : 0); |
| 731 |
} |
| 732 |
|
| 733 |
static int imx95_pcie_enable_ref_clk(struct imx_pcie *imx_pcie, bool enable) |
| 734 |
{ |
| 735 |
imx95_pcie_clkreq_override(imx_pcie, enable); |
| 736 |
return 0; |
| 737 |
} |
| 738 |
|
| 739 |
static void imx8mm_pcie_clr_clkreq_override(struct imx_pcie *imx_pcie) |
| 740 |
{ |
| 741 |
imx8mm_pcie_clkreq_override(imx_pcie, false); |
| 742 |
} |
| 743 |
|
| 744 |
static void imx95_pcie_clr_clkreq_override(struct imx_pcie *imx_pcie) |
| 745 |
{ |
| 746 |
imx95_pcie_clkreq_override(imx_pcie, false); |
| 747 |
} |
| 748 |
|
| 749 |
static int imx_pcie_clk_enable(struct imx_pcie *imx_pcie) |
| 750 |
{ |
| 751 |
struct dw_pcie *pci = imx_pcie->pci; |
| 752 |
struct device *dev = pci->dev; |
| 753 |
int ret; |
| 754 |
|
| 755 |
ret = clk_bulk_prepare_enable(imx_pcie->num_clks, imx_pcie->clks); |
| 756 |
if (ret) |
| 757 |
return ret; |
| 758 |
|
| 759 |
if (imx_pcie->drvdata->enable_ref_clk) { |
| 760 |
ret = imx_pcie->drvdata->enable_ref_clk(imx_pcie, true); |
| 761 |
if (ret) { |
| 762 |
dev_err(dev, "Failed to enable PCIe REFCLK\n"); |
| 763 |
goto err_ref_clk; |
| 764 |
} |
| 765 |
} |
| 766 |
|
| 767 |
/* allow the clocks to stabilize */ |
| 768 |
usleep_range(200, 500); |
| 769 |
return 0; |
| 770 |
|
| 771 |
err_ref_clk: |
| 772 |
clk_bulk_disable_unprepare(imx_pcie->num_clks, imx_pcie->clks); |
| 773 |
|
| 774 |
return ret; |
| 775 |
} |
| 776 |
|
| 777 |
static void imx_pcie_clk_disable(struct imx_pcie *imx_pcie) |
| 778 |
{ |
| 779 |
if (imx_pcie->drvdata->enable_ref_clk) |
| 780 |
imx_pcie->drvdata->enable_ref_clk(imx_pcie, false); |
| 781 |
clk_bulk_disable_unprepare(imx_pcie->num_clks, imx_pcie->clks); |
| 782 |
} |
| 783 |
|
| 784 |
static int imx6sx_pcie_core_reset(struct imx_pcie *imx_pcie, bool assert) |
| 785 |
{ |
| 786 |
if (assert) |
| 787 |
regmap_set_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 788 |
IMX6SX_GPR12_PCIE_TEST_POWERDOWN); |
| 789 |
|
| 790 |
/* Force PCIe PHY reset */ |
| 791 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR5, IMX6SX_GPR5_PCIE_BTNRST_RESET, |
| 792 |
assert ? IMX6SX_GPR5_PCIE_BTNRST_RESET : 0); |
| 793 |
return 0; |
| 794 |
} |
| 795 |
|
| 796 |
static int imx6qp_pcie_core_reset(struct imx_pcie *imx_pcie, bool assert) |
| 797 |
{ |
| 798 |
regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_SW_RST, |
| 799 |
assert ? IMX6Q_GPR1_PCIE_SW_RST : 0); |
| 800 |
if (!assert) |
| 801 |
usleep_range(200, 500); |
| 802 |
|
| 803 |
return 0; |
| 804 |
} |
| 805 |
|
| 806 |
static int imx6q_pcie_core_reset(struct imx_pcie *imx_pcie, bool assert) |
| 807 |
{ |
| 808 |
if (!assert) |
| 809 |
return 0; |
| 810 |
|
| 811 |
regmap_set_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_TEST_PD); |
| 812 |
regmap_set_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_REF_CLK_EN); |
| 813 |
|
| 814 |
return 0; |
| 815 |
} |
| 816 |
|
| 817 |
static int imx7d_pcie_core_reset(struct imx_pcie *imx_pcie, bool assert) |
| 818 |
{ |
| 819 |
struct dw_pcie *pci = imx_pcie->pci; |
| 820 |
struct device *dev = pci->dev; |
| 821 |
|
| 822 |
if (assert) |
| 823 |
return 0; |
| 824 |
|
| 825 |
/* |
| 826 |
* Workaround for ERR010728 (IMX7DS_2N09P, Rev. 1.1, 4/2023): |
| 827 |
* |
| 828 |
* PCIe: PLL may fail to lock under corner conditions. |
| 829 |
* |
| 830 |
* Initial VCO oscillation may fail under corner conditions such as |
| 831 |
* cold temperature which will cause the PCIe PLL fail to lock in the |
| 832 |
* initialization phase. |
| 833 |
* |
| 834 |
* The Duty-cycle Corrector calibration must be disabled. |
| 835 |
* |
| 836 |
* 1. De-assert the G_RST signal by clearing |
| 837 |
* SRC_PCIEPHY_RCR[PCIEPHY_G_RST]. |
| 838 |
* 2. De-assert DCC_FB_EN by writing data “0x29” to the register |
| 839 |
* address 0x306d0014 (PCIE_PHY_CMN_REG4). |
| 840 |
* 3. Assert RX_EQS, RX_EQ_SEL by writing data “0x48” to the register |
| 841 |
* address 0x306d0090 (PCIE_PHY_CMN_REG24). |
| 842 |
* 4. Assert ATT_MODE by writing data “0xbc” to the register |
| 843 |
* address 0x306d0098 (PCIE_PHY_CMN_REG26). |
| 844 |
* 5. De-assert the CMN_RST signal by clearing register bit |
| 845 |
* SRC_PCIEPHY_RCR[PCIEPHY_BTN] |
| 846 |
*/ |
| 847 |
|
| 848 |
if (likely(imx_pcie->phy_base)) { |
| 849 |
/* De-assert DCC_FB_EN */ |
| 850 |
writel(PCIE_PHY_CMN_REG4_DCC_FB_EN, imx_pcie->phy_base + PCIE_PHY_CMN_REG4); |
| 851 |
/* Assert RX_EQS and RX_EQS_SEL */ |
| 852 |
writel(PCIE_PHY_CMN_REG24_RX_EQ_SEL | PCIE_PHY_CMN_REG24_RX_EQ, |
| 853 |
imx_pcie->phy_base + PCIE_PHY_CMN_REG24); |
| 854 |
/* Assert ATT_MODE */ |
| 855 |
writel(PCIE_PHY_CMN_REG26_ATT_MODE, imx_pcie->phy_base + PCIE_PHY_CMN_REG26); |
| 856 |
} else { |
| 857 |
dev_warn(dev, "Unable to apply ERR010728 workaround. DT missing fsl,imx7d-pcie-phy phandle ?\n"); |
| 858 |
} |
| 859 |
imx7d_pcie_wait_for_phy_pll_lock(imx_pcie); |
| 860 |
return 0; |
| 861 |
} |
| 862 |
|
| 863 |
static int imx95_pcie_core_reset(struct imx_pcie *imx_pcie, bool assert) |
| 864 |
{ |
| 865 |
u32 val; |
| 866 |
|
| 867 |
if (assert) { |
| 868 |
/* |
| 869 |
* From i.MX95 PCIe PHY perspective, the COLD reset toggle |
| 870 |
* should be complete after power-up by the following sequence. |
| 871 |
* > 10us(at power-up) |
| 872 |
* > 10ns(warm reset) |
| 873 |
* |<------------>| |
| 874 |
* ______________ |
| 875 |
* phy_reset ____/ \________________ |
| 876 |
* ____________ |
| 877 |
* ref_clk_en_______________________/ |
| 878 |
* Toggle COLD reset aligned with this sequence for i.MX95 PCIe. |
| 879 |
*/ |
| 880 |
regmap_set_bits(imx_pcie->iomuxc_gpr, IMX95_PCIE_RST_CTRL, |
| 881 |
IMX95_PCIE_COLD_RST); |
| 882 |
/* |
| 883 |
* Make sure the write to IMX95_PCIE_RST_CTRL is flushed to the |
| 884 |
* hardware by doing a read. Otherwise, there is no guarantee |
| 885 |
* that the write has reached the hardware before udelay(). |
| 886 |
*/ |
| 887 |
regmap_read_bypassed(imx_pcie->iomuxc_gpr, IMX95_PCIE_RST_CTRL, |
| 888 |
&val); |
| 889 |
udelay(15); |
| 890 |
regmap_clear_bits(imx_pcie->iomuxc_gpr, IMX95_PCIE_RST_CTRL, |
| 891 |
IMX95_PCIE_COLD_RST); |
| 892 |
regmap_read_bypassed(imx_pcie->iomuxc_gpr, IMX95_PCIE_RST_CTRL, |
| 893 |
&val); |
| 894 |
udelay(10); |
| 895 |
} |
| 896 |
|
| 897 |
return 0; |
| 898 |
} |
| 899 |
|
| 900 |
static void imx_pcie_assert_core_reset(struct imx_pcie *imx_pcie) |
| 901 |
{ |
| 902 |
reset_control_assert(imx_pcie->pciephy_reset); |
| 903 |
|
| 904 |
if (imx_pcie->drvdata->core_reset) |
| 905 |
imx_pcie->drvdata->core_reset(imx_pcie, true); |
| 906 |
|
| 907 |
/* Some boards don't have PCIe reset GPIO. */ |
| 908 |
gpiod_set_value_cansleep(imx_pcie->reset_gpiod, 1); |
| 909 |
} |
| 910 |
|
| 911 |
static int imx_pcie_deassert_core_reset(struct imx_pcie *imx_pcie) |
| 912 |
{ |
| 913 |
reset_control_deassert(imx_pcie->pciephy_reset); |
| 914 |
|
| 915 |
if (imx_pcie->drvdata->core_reset) |
| 916 |
imx_pcie->drvdata->core_reset(imx_pcie, false); |
| 917 |
|
| 918 |
/* Some boards don't have PCIe reset GPIO. */ |
| 919 |
if (imx_pcie->reset_gpiod) { |
| 920 |
msleep(100); |
| 921 |
gpiod_set_value_cansleep(imx_pcie->reset_gpiod, 0); |
| 922 |
/* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */ |
| 923 |
msleep(100); |
| 924 |
} |
| 925 |
|
| 926 |
return 0; |
| 927 |
} |
| 928 |
|
| 929 |
static int imx_pcie_wait_for_speed_change(struct imx_pcie *imx_pcie) |
| 930 |
{ |
| 931 |
struct dw_pcie *pci = imx_pcie->pci; |
| 932 |
struct device *dev = pci->dev; |
| 933 |
u32 tmp; |
| 934 |
unsigned int retries; |
| 935 |
|
| 936 |
for (retries = 0; retries < 200; retries++) { |
| 937 |
tmp = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL); |
| 938 |
/* Test if the speed change finished. */ |
| 939 |
if (!(tmp & PORT_LOGIC_SPEED_CHANGE)) |
| 940 |
return 0; |
| 941 |
usleep_range(100, 1000); |
| 942 |
} |
| 943 |
|
| 944 |
dev_err(dev, "Speed change timeout\n"); |
| 945 |
return -ETIMEDOUT; |
| 946 |
} |
| 947 |
|
| 948 |
static void imx_pcie_ltssm_enable(struct device *dev) |
| 949 |
{ |
| 950 |
struct imx_pcie *imx_pcie = dev_get_drvdata(dev); |
| 951 |
const struct imx_pcie_drvdata *drvdata = imx_pcie->drvdata; |
| 952 |
u8 offset = dw_pcie_find_capability(imx_pcie->pci, PCI_CAP_ID_EXP); |
| 953 |
u32 tmp; |
| 954 |
|
| 955 |
tmp = dw_pcie_readl_dbi(imx_pcie->pci, offset + PCI_EXP_LNKCAP); |
| 956 |
phy_set_speed(imx_pcie->phy, FIELD_GET(PCI_EXP_LNKCAP_SLS, tmp)); |
| 957 |
if (drvdata->ltssm_mask) |
| 958 |
regmap_update_bits(imx_pcie->iomuxc_gpr, drvdata->ltssm_off, drvdata->ltssm_mask, |
| 959 |
drvdata->ltssm_mask); |
| 960 |
|
| 961 |
reset_control_deassert(imx_pcie->apps_reset); |
| 962 |
} |
| 963 |
|
| 964 |
static void imx_pcie_ltssm_disable(struct device *dev) |
| 965 |
{ |
| 966 |
struct imx_pcie *imx_pcie = dev_get_drvdata(dev); |
| 967 |
const struct imx_pcie_drvdata *drvdata = imx_pcie->drvdata; |
| 968 |
|
| 969 |
phy_set_speed(imx_pcie->phy, 0); |
| 970 |
if (drvdata->ltssm_mask) |
| 971 |
regmap_update_bits(imx_pcie->iomuxc_gpr, drvdata->ltssm_off, |
| 972 |
drvdata->ltssm_mask, 0); |
| 973 |
|
| 974 |
reset_control_assert(imx_pcie->apps_reset); |
| 975 |
} |
| 976 |
|
| 977 |
static int imx_pcie_start_link(struct dw_pcie *pci) |
| 978 |
{ |
| 979 |
struct imx_pcie *imx_pcie = to_imx_pcie(pci); |
| 980 |
struct device *dev = pci->dev; |
| 981 |
u8 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); |
| 982 |
u32 tmp; |
| 983 |
int ret; |
| 984 |
|
| 985 |
if (!(imx_pcie->drvdata->flags & |
| 986 |
IMX_PCIE_FLAG_SPEED_CHANGE_WORKAROUND)) { |
| 987 |
imx_pcie_ltssm_enable(dev); |
| 988 |
return 0; |
| 989 |
} |
| 990 |
|
| 991 |
/* |
| 992 |
* Force Gen1 operation when starting the link. In case the link is |
| 993 |
* started in Gen2 mode, there is a possibility the devices on the |
| 994 |
* bus will not be detected at all. This happens with PCIe switches. |
| 995 |
*/ |
| 996 |
dw_pcie_dbi_ro_wr_en(pci); |
| 997 |
tmp = dw_pcie_readl_dbi(pci, offset + PCI_EXP_LNKCAP); |
| 998 |
tmp &= ~PCI_EXP_LNKCAP_SLS; |
| 999 |
tmp |= PCI_EXP_LNKCAP_SLS_2_5GB; |
| 1000 |
dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCAP, tmp); |
| 1001 |
dw_pcie_dbi_ro_wr_dis(pci); |
| 1002 |
|
| 1003 |
/* Start LTSSM. */ |
| 1004 |
imx_pcie_ltssm_enable(dev); |
| 1005 |
|
| 1006 |
if (pci->max_link_speed > 1) { |
| 1007 |
ret = dw_pcie_wait_for_link(pci); |
| 1008 |
if (ret) |
| 1009 |
goto err_reset_phy; |
| 1010 |
|
| 1011 |
/* Allow faster modes after the link is up */ |
| 1012 |
dw_pcie_dbi_ro_wr_en(pci); |
| 1013 |
tmp = dw_pcie_readl_dbi(pci, offset + PCI_EXP_LNKCAP); |
| 1014 |
tmp &= ~PCI_EXP_LNKCAP_SLS; |
| 1015 |
tmp |= pci->max_link_speed; |
| 1016 |
dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCAP, tmp); |
| 1017 |
|
| 1018 |
/* |
| 1019 |
* Start Directed Speed Change so the best possible |
| 1020 |
* speed both link partners support can be negotiated. |
| 1021 |
*/ |
| 1022 |
tmp = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL); |
| 1023 |
tmp |= PORT_LOGIC_SPEED_CHANGE; |
| 1024 |
dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, tmp); |
| 1025 |
dw_pcie_dbi_ro_wr_dis(pci); |
| 1026 |
|
| 1027 |
ret = imx_pcie_wait_for_speed_change(imx_pcie); |
| 1028 |
if (ret) { |
| 1029 |
dev_err(dev, "Failed to bring link up!\n"); |
| 1030 |
goto err_reset_phy; |
| 1031 |
} |
| 1032 |
} else { |
| 1033 |
dev_info(dev, "Link: Only Gen1 is enabled\n"); |
| 1034 |
} |
| 1035 |
|
| 1036 |
return 0; |
| 1037 |
|
| 1038 |
err_reset_phy: |
| 1039 |
dev_dbg(dev, "PHY DEBUG_R0=0x%08x DEBUG_R1=0x%08x\n", |
| 1040 |
dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG0), |
| 1041 |
dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG1)); |
| 1042 |
imx_pcie_reset_phy(imx_pcie); |
| 1043 |
return 0; |
| 1044 |
} |
| 1045 |
|
| 1046 |
static void imx_pcie_stop_link(struct dw_pcie *pci) |
| 1047 |
{ |
| 1048 |
struct device *dev = pci->dev; |
| 1049 |
|
| 1050 |
/* Turn off PCIe LTSSM */ |
| 1051 |
imx_pcie_ltssm_disable(dev); |
| 1052 |
} |
| 1053 |
|
| 1054 |
static int imx_pcie_add_lut(struct imx_pcie *imx_pcie, u16 rid, u8 sid) |
| 1055 |
{ |
| 1056 |
struct dw_pcie *pci = imx_pcie->pci; |
| 1057 |
struct device *dev = pci->dev; |
| 1058 |
u32 data1, data2; |
| 1059 |
int free = -1; |
| 1060 |
int i; |
| 1061 |
|
| 1062 |
if (sid >= 64) { |
| 1063 |
dev_err(dev, "Invalid SID for index %d\n", sid); |
| 1064 |
return -EINVAL; |
| 1065 |
} |
| 1066 |
|
| 1067 |
guard(mutex)(&imx_pcie->lock); |
| 1068 |
|
| 1069 |
/* |
| 1070 |
* Iterate through all LUT entries to check for duplicate RID and |
| 1071 |
* identify the first available entry. Configure this available entry |
| 1072 |
* immediately after verification to avoid rescanning it. |
| 1073 |
*/ |
| 1074 |
for (i = 0; i < IMX95_MAX_LUT; i++) { |
| 1075 |
regmap_write(imx_pcie->iomuxc_gpr, |
| 1076 |
IMX95_PE0_LUT_ACSCTRL, IMX95_PEO_LUT_RWA | i); |
| 1077 |
regmap_read(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA1, &data1); |
| 1078 |
|
| 1079 |
if (!(data1 & IMX95_PE0_LUT_VLD)) { |
| 1080 |
if (free < 0) |
| 1081 |
free = i; |
| 1082 |
continue; |
| 1083 |
} |
| 1084 |
|
| 1085 |
regmap_read(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA2, &data2); |
| 1086 |
|
| 1087 |
/* Do not add duplicate RID */ |
| 1088 |
if (rid == FIELD_GET(IMX95_PE0_LUT_REQID, data2)) { |
| 1089 |
dev_warn(dev, "Existing LUT entry available for RID (%d)", rid); |
| 1090 |
return 0; |
| 1091 |
} |
| 1092 |
} |
| 1093 |
|
| 1094 |
if (free < 0) { |
| 1095 |
dev_err(dev, "LUT entry is not available\n"); |
| 1096 |
return -ENOSPC; |
| 1097 |
} |
| 1098 |
|
| 1099 |
data1 = FIELD_PREP(IMX95_PE0_LUT_DAC_ID, 0); |
| 1100 |
data1 |= FIELD_PREP(IMX95_PE0_LUT_STREAM_ID, sid); |
| 1101 |
data1 |= IMX95_PE0_LUT_VLD; |
| 1102 |
regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA1, data1); |
| 1103 |
|
| 1104 |
if (imx_pcie->drvdata->mode == DW_PCIE_EP_TYPE) |
| 1105 |
data2 = 0x7; /* In the EP mode, only 'Device ID' is required */ |
| 1106 |
else |
| 1107 |
data2 = IMX95_PE0_LUT_MASK; /* Match all bits of RID */ |
| 1108 |
data2 |= FIELD_PREP(IMX95_PE0_LUT_REQID, rid); |
| 1109 |
regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA2, data2); |
| 1110 |
|
| 1111 |
regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_ACSCTRL, free); |
| 1112 |
|
| 1113 |
return 0; |
| 1114 |
} |
| 1115 |
|
| 1116 |
static void imx_pcie_remove_lut(struct imx_pcie *imx_pcie, u16 rid) |
| 1117 |
{ |
| 1118 |
u32 data2; |
| 1119 |
int i; |
| 1120 |
|
| 1121 |
guard(mutex)(&imx_pcie->lock); |
| 1122 |
|
| 1123 |
for (i = 0; i < IMX95_MAX_LUT; i++) { |
| 1124 |
regmap_write(imx_pcie->iomuxc_gpr, |
| 1125 |
IMX95_PE0_LUT_ACSCTRL, IMX95_PEO_LUT_RWA | i); |
| 1126 |
regmap_read(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA2, &data2); |
| 1127 |
if (FIELD_GET(IMX95_PE0_LUT_REQID, data2) == rid) { |
| 1128 |
regmap_write(imx_pcie->iomuxc_gpr, |
| 1129 |
IMX95_PE0_LUT_DATA1, 0); |
| 1130 |
regmap_write(imx_pcie->iomuxc_gpr, |
| 1131 |
IMX95_PE0_LUT_DATA2, 0); |
| 1132 |
regmap_write(imx_pcie->iomuxc_gpr, |
| 1133 |
IMX95_PE0_LUT_ACSCTRL, i); |
| 1134 |
|
| 1135 |
break; |
| 1136 |
} |
| 1137 |
} |
| 1138 |
} |
| 1139 |
|
| 1140 |
static int imx_pcie_add_lut_by_rid(struct imx_pcie *imx_pcie, u32 rid) |
| 1141 |
{ |
| 1142 |
struct device *dev = imx_pcie->pci->dev; |
| 1143 |
struct device_node *target; |
| 1144 |
u32 sid_i, sid_m; |
| 1145 |
int err_i, err_m; |
| 1146 |
u32 sid = 0; |
| 1147 |
|
| 1148 |
target = NULL; |
| 1149 |
err_i = of_map_id(dev->of_node, rid, "iommu-map", "iommu-map-mask", |
| 1150 |
&target, &sid_i); |
| 1151 |
if (target) { |
| 1152 |
of_node_put(target); |
| 1153 |
} else { |
| 1154 |
/* |
| 1155 |
* "target == NULL && err_i == 0" means RID out of map range. |
| 1156 |
* Use 1:1 map RID to streamID. Hardware can't support this |
| 1157 |
* because the streamID is only 6 bits |
| 1158 |
*/ |
| 1159 |
err_i = -EINVAL; |
| 1160 |
} |
| 1161 |
|
| 1162 |
target = NULL; |
| 1163 |
err_m = of_map_id(dev->of_node, rid, "msi-map", "msi-map-mask", |
| 1164 |
&target, &sid_m); |
| 1165 |
|
| 1166 |
/* |
| 1167 |
* err_m target |
| 1168 |
* 0 NULL RID out of range. Use 1:1 map RID to |
| 1169 |
* streamID, Current hardware can't |
| 1170 |
* support it, so return -EINVAL. |
| 1171 |
* != 0 NULL msi-map does not exist, use built-in MSI |
| 1172 |
* 0 != NULL Get correct streamID from RID |
| 1173 |
* != 0 != NULL Invalid combination |
| 1174 |
*/ |
| 1175 |
if (!err_m && !target) |
| 1176 |
return -EINVAL; |
| 1177 |
else if (target) |
| 1178 |
of_node_put(target); /* Find streamID map entry for RID in msi-map */ |
| 1179 |
|
| 1180 |
/* |
| 1181 |
* msi-map iommu-map |
| 1182 |
* N N DWC MSI Ctrl |
| 1183 |
* Y Y ITS + SMMU, require the same SID |
| 1184 |
* Y N ITS |
| 1185 |
* N Y DWC MSI Ctrl + SMMU |
| 1186 |
*/ |
| 1187 |
if (err_i && err_m) |
| 1188 |
return 0; |
| 1189 |
|
| 1190 |
if (!err_i && !err_m) { |
| 1191 |
/* |
| 1192 |
* Glue Layer |
| 1193 |
* <==========> |
| 1194 |
* ┌─────┐ ┌──────────┐ |
| 1195 |
* │ LUT │ 6-bit streamID │ │ |
| 1196 |
* │ │─────────────────►│ MSI │ |
| 1197 |
* └─────┘ 2-bit ctrl ID │ │ |
| 1198 |
* ┌───────────►│ │ |
| 1199 |
* (i.MX95) │ │ │ |
| 1200 |
* 00 PCIe0 │ │ │ |
| 1201 |
* 01 ENETC │ │ │ |
| 1202 |
* 10 PCIe1 │ │ │ |
| 1203 |
* │ └──────────┘ |
| 1204 |
* The MSI glue layer auto adds 2 bits controller ID ahead of |
| 1205 |
* streamID, so mask these 2 bits to get streamID. The |
| 1206 |
* IOMMU glue layer doesn't do that. |
| 1207 |
*/ |
| 1208 |
if (sid_i != (sid_m & IMX95_SID_MASK)) { |
| 1209 |
dev_err(dev, "iommu-map and msi-map entries mismatch!\n"); |
| 1210 |
return -EINVAL; |
| 1211 |
} |
| 1212 |
} |
| 1213 |
|
| 1214 |
if (!err_i) |
| 1215 |
sid = sid_i; |
| 1216 |
else if (!err_m) |
| 1217 |
sid = sid_m & IMX95_SID_MASK; |
| 1218 |
|
| 1219 |
return imx_pcie_add_lut(imx_pcie, rid, sid); |
| 1220 |
} |
| 1221 |
|
| 1222 |
static int imx_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_dev *pdev) |
| 1223 |
{ |
| 1224 |
struct imx_pcie *imx_pcie = to_imx_pcie(to_dw_pcie_from_pp(bridge->sysdata)); |
| 1225 |
|
| 1226 |
return imx_pcie_add_lut_by_rid(imx_pcie, pci_dev_id(pdev)); |
| 1227 |
} |
| 1228 |
|
| 1229 |
static void imx_pcie_disable_device(struct pci_host_bridge *bridge, |
| 1230 |
struct pci_dev *pdev) |
| 1231 |
{ |
| 1232 |
struct imx_pcie *imx_pcie; |
| 1233 |
|
| 1234 |
imx_pcie = to_imx_pcie(to_dw_pcie_from_pp(bridge->sysdata)); |
| 1235 |
imx_pcie_remove_lut(imx_pcie, pci_dev_id(pdev)); |
| 1236 |
} |
| 1237 |
|
| 1238 |
static int imx_pcie_host_init(struct dw_pcie_rp *pp) |
| 1239 |
{ |
| 1240 |
struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
| 1241 |
struct device *dev = pci->dev; |
| 1242 |
struct imx_pcie *imx_pcie = to_imx_pcie(pci); |
| 1243 |
int ret; |
| 1244 |
|
| 1245 |
if (imx_pcie->vpcie) { |
| 1246 |
ret = regulator_enable(imx_pcie->vpcie); |
| 1247 |
if (ret) { |
| 1248 |
dev_err(dev, "failed to enable vpcie regulator: %d\n", |
| 1249 |
ret); |
| 1250 |
return ret; |
| 1251 |
} |
| 1252 |
} |
| 1253 |
|
| 1254 |
if (pp->bridge && imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_LUT)) { |
| 1255 |
pp->bridge->enable_device = imx_pcie_enable_device; |
| 1256 |
pp->bridge->disable_device = imx_pcie_disable_device; |
| 1257 |
} |
| 1258 |
|
| 1259 |
imx_pcie_assert_core_reset(imx_pcie); |
| 1260 |
|
| 1261 |
if (imx_pcie->drvdata->init_phy) |
| 1262 |
imx_pcie->drvdata->init_phy(imx_pcie); |
| 1263 |
|
| 1264 |
imx_pcie_configure_type(imx_pcie); |
| 1265 |
|
| 1266 |
ret = imx_pcie_clk_enable(imx_pcie); |
| 1267 |
if (ret) { |
| 1268 |
dev_err(dev, "unable to enable pcie clocks: %d\n", ret); |
| 1269 |
goto err_reg_disable; |
| 1270 |
} |
| 1271 |
|
| 1272 |
if (imx_pcie->phy) { |
| 1273 |
ret = phy_init(imx_pcie->phy); |
| 1274 |
if (ret) { |
| 1275 |
dev_err(dev, "pcie PHY power up failed\n"); |
| 1276 |
goto err_clk_disable; |
| 1277 |
} |
| 1278 |
|
| 1279 |
ret = phy_set_mode_ext(imx_pcie->phy, PHY_MODE_PCIE, |
| 1280 |
imx_pcie->drvdata->mode == DW_PCIE_EP_TYPE ? |
| 1281 |
PHY_MODE_PCIE_EP : PHY_MODE_PCIE_RC); |
| 1282 |
if (ret) { |
| 1283 |
dev_err(dev, "unable to set PCIe PHY mode\n"); |
| 1284 |
goto err_phy_exit; |
| 1285 |
} |
| 1286 |
|
| 1287 |
ret = phy_power_on(imx_pcie->phy); |
| 1288 |
if (ret) { |
| 1289 |
dev_err(dev, "waiting for PHY ready timeout!\n"); |
| 1290 |
goto err_phy_exit; |
| 1291 |
} |
| 1292 |
} |
| 1293 |
|
| 1294 |
/* Make sure that PCIe LTSSM is cleared */ |
| 1295 |
imx_pcie_ltssm_disable(dev); |
| 1296 |
|
| 1297 |
ret = imx_pcie_deassert_core_reset(imx_pcie); |
| 1298 |
if (ret < 0) { |
| 1299 |
dev_err(dev, "pcie deassert core reset failed: %d\n", ret); |
| 1300 |
goto err_phy_off; |
| 1301 |
} |
| 1302 |
|
| 1303 |
if (imx_pcie->drvdata->wait_pll_lock) { |
| 1304 |
ret = imx_pcie->drvdata->wait_pll_lock(imx_pcie); |
| 1305 |
if (ret < 0) |
| 1306 |
goto err_phy_off; |
| 1307 |
} |
| 1308 |
|
| 1309 |
imx_setup_phy_mpll(imx_pcie); |
| 1310 |
|
| 1311 |
return 0; |
| 1312 |
|
| 1313 |
err_phy_off: |
| 1314 |
phy_power_off(imx_pcie->phy); |
| 1315 |
err_phy_exit: |
| 1316 |
phy_exit(imx_pcie->phy); |
| 1317 |
err_clk_disable: |
| 1318 |
imx_pcie_clk_disable(imx_pcie); |
| 1319 |
err_reg_disable: |
| 1320 |
if (imx_pcie->vpcie) |
| 1321 |
regulator_disable(imx_pcie->vpcie); |
| 1322 |
return ret; |
| 1323 |
} |
| 1324 |
|
| 1325 |
static void imx_pcie_host_exit(struct dw_pcie_rp *pp) |
| 1326 |
{ |
| 1327 |
struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
| 1328 |
struct imx_pcie *imx_pcie = to_imx_pcie(pci); |
| 1329 |
|
| 1330 |
if (imx_pcie->phy) { |
| 1331 |
if (phy_power_off(imx_pcie->phy)) |
| 1332 |
dev_err(pci->dev, "unable to power off PHY\n"); |
| 1333 |
phy_exit(imx_pcie->phy); |
| 1334 |
} |
| 1335 |
imx_pcie_clk_disable(imx_pcie); |
| 1336 |
|
| 1337 |
if (imx_pcie->vpcie) |
| 1338 |
regulator_disable(imx_pcie->vpcie); |
| 1339 |
} |
| 1340 |
|
| 1341 |
static void imx_pcie_host_post_init(struct dw_pcie_rp *pp) |
| 1342 |
{ |
| 1343 |
struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
| 1344 |
struct imx_pcie *imx_pcie = to_imx_pcie(pci); |
| 1345 |
u32 val; |
| 1346 |
|
| 1347 |
if (imx_pcie->drvdata->flags & IMX_PCIE_FLAG_8GT_ECN_ERR051586) { |
| 1348 |
/* |
| 1349 |
* ERR051586: Compliance with 8GT/s Receiver Impedance ECN |
| 1350 |
* |
| 1351 |
* The default value of GEN3_RELATED_OFF[GEN3_ZRXDC_NONCOMPL] |
| 1352 |
* is 1 which makes receiver non-compliant with the ZRX-DC |
| 1353 |
* parameter for 2.5 GT/s when operating at 8 GT/s or higher. |
| 1354 |
* It causes unnecessary timeout in L1. |
| 1355 |
* |
| 1356 |
* Workaround: Program GEN3_RELATED_OFF[GEN3_ZRXDC_NONCOMPL] |
| 1357 |
* to 0. |
| 1358 |
*/ |
| 1359 |
dw_pcie_dbi_ro_wr_en(pci); |
| 1360 |
val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF); |
| 1361 |
val &= ~GEN3_RELATED_OFF_GEN3_ZRXDC_NONCOMPL; |
| 1362 |
dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val); |
| 1363 |
dw_pcie_dbi_ro_wr_dis(pci); |
| 1364 |
} |
| 1365 |
|
| 1366 |
/* Clear CLKREQ# override if supports_clkreq is true and link is up */ |
| 1367 |
if (dw_pcie_link_up(pci) && imx_pcie->supports_clkreq) { |
| 1368 |
if (imx_pcie->drvdata->clr_clkreq_override) |
| 1369 |
imx_pcie->drvdata->clr_clkreq_override(imx_pcie); |
| 1370 |
} |
| 1371 |
} |
| 1372 |
|
| 1373 |
/* |
| 1374 |
* In old DWC implementations, PCIE_ATU_INHIBIT_PAYLOAD in iATU Ctrl2 |
| 1375 |
* register is reserved, so the generic DWC implementation of sending the |
| 1376 |
* PME_Turn_Off message using a dummy MMIO write cannot be used. |
| 1377 |
*/ |
| 1378 |
static void imx_pcie_pme_turn_off(struct dw_pcie_rp *pp) |
| 1379 |
{ |
| 1380 |
struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
| 1381 |
struct imx_pcie *imx_pcie = to_imx_pcie(pci); |
| 1382 |
|
| 1383 |
regmap_set_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, IMX6SX_GPR12_PCIE_PM_TURN_OFF); |
| 1384 |
regmap_clear_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, IMX6SX_GPR12_PCIE_PM_TURN_OFF); |
| 1385 |
|
| 1386 |
usleep_range(PCIE_PME_TO_L2_TIMEOUT_US/10, PCIE_PME_TO_L2_TIMEOUT_US); |
| 1387 |
} |
| 1388 |
|
| 1389 |
static const struct dw_pcie_host_ops imx_pcie_host_ops = { |
| 1390 |
.init = imx_pcie_host_init, |
| 1391 |
.deinit = imx_pcie_host_exit, |
| 1392 |
.pme_turn_off = imx_pcie_pme_turn_off, |
| 1393 |
}; |
| 1394 |
|
| 1395 |
static const struct dw_pcie_host_ops imx_pcie_host_dw_pme_ops = { |
| 1396 |
.init = imx_pcie_host_init, |
| 1397 |
.deinit = imx_pcie_host_exit, |
| 1398 |
.post_init = imx_pcie_host_post_init, |
| 1399 |
}; |
| 1400 |
|
| 1401 |
static const struct dw_pcie_ops dw_pcie_ops = { |
| 1402 |
.start_link = imx_pcie_start_link, |
| 1403 |
.stop_link = imx_pcie_stop_link, |
| 1404 |
}; |
| 1405 |
|
| 1406 |
static void imx_pcie_ep_init(struct dw_pcie_ep *ep) |
| 1407 |
{ |
| 1408 |
enum pci_barno bar; |
| 1409 |
struct dw_pcie *pci = to_dw_pcie_from_ep(ep); |
| 1410 |
|
| 1411 |
for (bar = BAR_0; bar <= BAR_5; bar++) |
| 1412 |
dw_pcie_ep_reset_bar(pci, bar); |
| 1413 |
} |
| 1414 |
|
| 1415 |
static int imx_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, |
| 1416 |
unsigned int type, u16 interrupt_num) |
| 1417 |
{ |
| 1418 |
struct dw_pcie *pci = to_dw_pcie_from_ep(ep); |
| 1419 |
|
| 1420 |
switch (type) { |
| 1421 |
case PCI_IRQ_INTX: |
| 1422 |
return dw_pcie_ep_raise_intx_irq(ep, func_no); |
| 1423 |
case PCI_IRQ_MSI: |
| 1424 |
return dw_pcie_ep_raise_msi_irq(ep, func_no, interrupt_num); |
| 1425 |
case PCI_IRQ_MSIX: |
| 1426 |
return dw_pcie_ep_raise_msix_irq(ep, func_no, interrupt_num); |
| 1427 |
default: |
| 1428 |
dev_err(pci->dev, "UNKNOWN IRQ type\n"); |
| 1429 |
return -EINVAL; |
| 1430 |
} |
| 1431 |
|
| 1432 |
return 0; |
| 1433 |
} |
| 1434 |
|
| 1435 |
static const struct pci_epc_features imx8m_pcie_epc_features = { |
| 1436 |
DWC_EPC_COMMON_FEATURES, |
| 1437 |
.msi_capable = true, |
| 1438 |
.bar[BAR_1] = { .type = BAR_RESERVED, }, |
| 1439 |
.bar[BAR_3] = { .type = BAR_RESERVED, }, |
| 1440 |
.bar[BAR_4] = { .type = BAR_FIXED, .fixed_size = SZ_256, }, |
| 1441 |
.bar[BAR_5] = { .type = BAR_RESERVED, }, |
| 1442 |
.align = SZ_64K, |
| 1443 |
}; |
| 1444 |
|
| 1445 |
static const struct pci_epc_features imx8q_pcie_epc_features = { |
| 1446 |
DWC_EPC_COMMON_FEATURES, |
| 1447 |
.msi_capable = true, |
| 1448 |
.bar[BAR_1] = { .type = BAR_RESERVED, }, |
| 1449 |
.bar[BAR_3] = { .type = BAR_RESERVED, }, |
| 1450 |
.bar[BAR_5] = { .type = BAR_RESERVED, }, |
| 1451 |
.align = SZ_64K, |
| 1452 |
}; |
| 1453 |
|
| 1454 |
/* |
| 1455 |
* | Default | Default | Default | BAR Sizing |
| 1456 |
* BAR# | Enable? | Type | Size | Scheme |
| 1457 |
* ======================================================= |
| 1458 |
* BAR0 | Enable | 64-bit | 1 MB | Programmable Size |
| 1459 |
* BAR1 | Disable | 32-bit | 64 KB | Fixed Size |
| 1460 |
* (BAR1 should be disabled if BAR0 is 64-bit) |
| 1461 |
* BAR2 | Enable | 32-bit | 1 MB | Programmable Size |
| 1462 |
* BAR3 | Enable | 32-bit | 64 KB | Programmable Size |
| 1463 |
* BAR4 | Enable | 32-bit | 1 MB | Programmable Size |
| 1464 |
* BAR5 | Enable | 32-bit | 64 KB | Programmable Size |
| 1465 |
*/ |
| 1466 |
static const struct pci_epc_features imx95_pcie_epc_features = { |
| 1467 |
DWC_EPC_COMMON_FEATURES, |
| 1468 |
.msi_capable = true, |
| 1469 |
.bar[BAR_1] = { .type = BAR_FIXED, .fixed_size = SZ_64K, }, |
| 1470 |
.align = SZ_4K, |
| 1471 |
}; |
| 1472 |
|
| 1473 |
static const struct pci_epc_features* |
| 1474 |
imx_pcie_ep_get_features(struct dw_pcie_ep *ep) |
| 1475 |
{ |
| 1476 |
struct dw_pcie *pci = to_dw_pcie_from_ep(ep); |
| 1477 |
struct imx_pcie *imx_pcie = to_imx_pcie(pci); |
| 1478 |
|
| 1479 |
return imx_pcie->drvdata->epc_features; |
| 1480 |
} |
| 1481 |
|
| 1482 |
static const struct dw_pcie_ep_ops pcie_ep_ops = { |
| 1483 |
.init = imx_pcie_ep_init, |
| 1484 |
.raise_irq = imx_pcie_ep_raise_irq, |
| 1485 |
.get_features = imx_pcie_ep_get_features, |
| 1486 |
}; |
| 1487 |
|
| 1488 |
static int imx_add_pcie_ep(struct imx_pcie *imx_pcie, |
| 1489 |
struct platform_device *pdev) |
| 1490 |
{ |
| 1491 |
int ret; |
| 1492 |
struct dw_pcie_ep *ep; |
| 1493 |
struct dw_pcie *pci = imx_pcie->pci; |
| 1494 |
struct dw_pcie_rp *pp = &pci->pp; |
| 1495 |
struct device *dev = pci->dev; |
| 1496 |
|
| 1497 |
imx_pcie_host_init(pp); |
| 1498 |
ep = &pci->ep; |
| 1499 |
ep->ops = &pcie_ep_ops; |
| 1500 |
|
| 1501 |
if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_SUPPORT_64BIT)) |
| 1502 |
dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); |
| 1503 |
|
| 1504 |
ep->page_size = imx_pcie->drvdata->epc_features->align; |
| 1505 |
|
| 1506 |
ret = dw_pcie_ep_init(ep); |
| 1507 |
if (ret) { |
| 1508 |
dev_err(dev, "failed to initialize endpoint\n"); |
| 1509 |
return ret; |
| 1510 |
} |
| 1511 |
imx_pcie_host_post_init(pp); |
| 1512 |
|
| 1513 |
ret = dw_pcie_ep_init_registers(ep); |
| 1514 |
if (ret) { |
| 1515 |
dev_err(dev, "Failed to initialize DWC endpoint registers\n"); |
| 1516 |
dw_pcie_ep_deinit(ep); |
| 1517 |
return ret; |
| 1518 |
} |
| 1519 |
|
| 1520 |
pci_epc_init_notify(ep->epc); |
| 1521 |
|
| 1522 |
return 0; |
| 1523 |
} |
| 1524 |
|
| 1525 |
static void imx_pcie_msi_save_restore(struct imx_pcie *imx_pcie, bool save) |
| 1526 |
{ |
| 1527 |
u8 offset; |
| 1528 |
u16 val; |
| 1529 |
struct dw_pcie *pci = imx_pcie->pci; |
| 1530 |
|
| 1531 |
if (pci_msi_enabled()) { |
| 1532 |
offset = dw_pcie_find_capability(pci, PCI_CAP_ID_MSI); |
| 1533 |
if (save) { |
| 1534 |
val = dw_pcie_readw_dbi(pci, offset + PCI_MSI_FLAGS); |
| 1535 |
imx_pcie->msi_ctrl = val; |
| 1536 |
} else { |
| 1537 |
dw_pcie_dbi_ro_wr_en(pci); |
| 1538 |
val = imx_pcie->msi_ctrl; |
| 1539 |
dw_pcie_writew_dbi(pci, offset + PCI_MSI_FLAGS, val); |
| 1540 |
dw_pcie_dbi_ro_wr_dis(pci); |
| 1541 |
} |
| 1542 |
} |
| 1543 |
} |
| 1544 |
|
| 1545 |
static void imx_pcie_lut_save(struct imx_pcie *imx_pcie) |
| 1546 |
{ |
| 1547 |
u32 data1, data2; |
| 1548 |
int i; |
| 1549 |
|
| 1550 |
for (i = 0; i < IMX95_MAX_LUT; i++) { |
| 1551 |
regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_ACSCTRL, |
| 1552 |
IMX95_PEO_LUT_RWA | i); |
| 1553 |
regmap_read(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA1, &data1); |
| 1554 |
regmap_read(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA2, &data2); |
| 1555 |
if (data1 & IMX95_PE0_LUT_VLD) { |
| 1556 |
imx_pcie->luts[i].data1 = data1; |
| 1557 |
imx_pcie->luts[i].data2 = data2; |
| 1558 |
} else { |
| 1559 |
imx_pcie->luts[i].data1 = 0; |
| 1560 |
imx_pcie->luts[i].data2 = 0; |
| 1561 |
} |
| 1562 |
} |
| 1563 |
} |
| 1564 |
|
| 1565 |
static void imx_pcie_lut_restore(struct imx_pcie *imx_pcie) |
| 1566 |
{ |
| 1567 |
int i; |
| 1568 |
|
| 1569 |
for (i = 0; i < IMX95_MAX_LUT; i++) { |
| 1570 |
if ((imx_pcie->luts[i].data1 & IMX95_PE0_LUT_VLD) == 0) |
| 1571 |
continue; |
| 1572 |
|
| 1573 |
regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA1, |
| 1574 |
imx_pcie->luts[i].data1); |
| 1575 |
regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA2, |
| 1576 |
imx_pcie->luts[i].data2); |
| 1577 |
regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_ACSCTRL, i); |
| 1578 |
} |
| 1579 |
} |
| 1580 |
|
| 1581 |
static int imx_pcie_suspend_noirq(struct device *dev) |
| 1582 |
{ |
| 1583 |
struct imx_pcie *imx_pcie = dev_get_drvdata(dev); |
| 1584 |
|
| 1585 |
if (!(imx_pcie->drvdata->flags & IMX_PCIE_FLAG_SUPPORTS_SUSPEND)) |
| 1586 |
return 0; |
| 1587 |
|
| 1588 |
imx_pcie_msi_save_restore(imx_pcie, true); |
| 1589 |
if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_LUT)) |
| 1590 |
imx_pcie_lut_save(imx_pcie); |
| 1591 |
if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_BROKEN_SUSPEND)) { |
| 1592 |
/* |
| 1593 |
* The minimum for a workaround would be to set PERST# and to |
| 1594 |
* set the PCIE_TEST_PD flag. However, we can also disable the |
| 1595 |
* clock which saves some power. |
| 1596 |
*/ |
| 1597 |
imx_pcie_assert_core_reset(imx_pcie); |
| 1598 |
imx_pcie->drvdata->enable_ref_clk(imx_pcie, false); |
| 1599 |
} else { |
| 1600 |
return dw_pcie_suspend_noirq(imx_pcie->pci); |
| 1601 |
} |
| 1602 |
|
| 1603 |
return 0; |
| 1604 |
} |
| 1605 |
|
| 1606 |
static int imx_pcie_resume_noirq(struct device *dev) |
| 1607 |
{ |
| 1608 |
int ret; |
| 1609 |
struct imx_pcie *imx_pcie = dev_get_drvdata(dev); |
| 1610 |
|
| 1611 |
if (!(imx_pcie->drvdata->flags & IMX_PCIE_FLAG_SUPPORTS_SUSPEND)) |
| 1612 |
return 0; |
| 1613 |
|
| 1614 |
if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_BROKEN_SUSPEND)) { |
| 1615 |
ret = imx_pcie->drvdata->enable_ref_clk(imx_pcie, true); |
| 1616 |
if (ret) |
| 1617 |
return ret; |
| 1618 |
ret = imx_pcie_deassert_core_reset(imx_pcie); |
| 1619 |
if (ret) |
| 1620 |
return ret; |
| 1621 |
|
| 1622 |
/* |
| 1623 |
* Using PCIE_TEST_PD seems to disable MSI and powers down the |
| 1624 |
* root complex. This is why we have to setup the rc again and |
| 1625 |
* why we have to restore the MSI register. |
| 1626 |
*/ |
| 1627 |
ret = dw_pcie_setup_rc(&imx_pcie->pci->pp); |
| 1628 |
if (ret) |
| 1629 |
return ret; |
| 1630 |
} else { |
| 1631 |
ret = dw_pcie_resume_noirq(imx_pcie->pci); |
| 1632 |
if (ret) |
| 1633 |
return ret; |
| 1634 |
} |
| 1635 |
if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_LUT)) |
| 1636 |
imx_pcie_lut_restore(imx_pcie); |
| 1637 |
imx_pcie_msi_save_restore(imx_pcie, false); |
| 1638 |
|
| 1639 |
return 0; |
| 1640 |
} |
| 1641 |
|
| 1642 |
static const struct dev_pm_ops imx_pcie_pm_ops = { |
| 1643 |
NOIRQ_SYSTEM_SLEEP_PM_OPS(imx_pcie_suspend_noirq, |
| 1644 |
imx_pcie_resume_noirq) |
| 1645 |
}; |
| 1646 |
|
| 1647 |
static int imx_pcie_probe(struct platform_device *pdev) |
| 1648 |
{ |
| 1649 |
struct device *dev = &pdev->dev; |
| 1650 |
struct dw_pcie *pci; |
| 1651 |
struct imx_pcie *imx_pcie; |
| 1652 |
struct device_node *node = dev->of_node; |
| 1653 |
int i, ret, domain; |
| 1654 |
u16 val; |
| 1655 |
|
| 1656 |
imx_pcie = devm_kzalloc(dev, sizeof(*imx_pcie), GFP_KERNEL); |
| 1657 |
if (!imx_pcie) |
| 1658 |
return -ENOMEM; |
| 1659 |
|
| 1660 |
pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); |
| 1661 |
if (!pci) |
| 1662 |
return -ENOMEM; |
| 1663 |
|
| 1664 |
pci->dev = dev; |
| 1665 |
pci->ops = &dw_pcie_ops; |
| 1666 |
|
| 1667 |
imx_pcie->pci = pci; |
| 1668 |
imx_pcie->drvdata = of_device_get_match_data(dev); |
| 1669 |
|
| 1670 |
mutex_init(&imx_pcie->lock); |
| 1671 |
|
| 1672 |
if (imx_pcie->drvdata->ops) |
| 1673 |
pci->pp.ops = imx_pcie->drvdata->ops; |
| 1674 |
else |
| 1675 |
pci->pp.ops = &imx_pcie_host_dw_pme_ops; |
| 1676 |
|
| 1677 |
/* Find the PHY if one is defined, only imx7d uses it */ |
| 1678 |
struct device_node *np __free(device_node) = |
| 1679 |
of_parse_phandle(node, "fsl,imx7d-pcie-phy", 0); |
| 1680 |
if (np) { |
| 1681 |
struct resource res; |
| 1682 |
|
| 1683 |
ret = of_address_to_resource(np, 0, &res); |
| 1684 |
if (ret) { |
| 1685 |
dev_err(dev, "Unable to map PCIe PHY\n"); |
| 1686 |
return ret; |
| 1687 |
} |
| 1688 |
imx_pcie->phy_base = devm_ioremap_resource(dev, &res); |
| 1689 |
if (IS_ERR(imx_pcie->phy_base)) |
| 1690 |
return PTR_ERR(imx_pcie->phy_base); |
| 1691 |
} |
| 1692 |
|
| 1693 |
/* Fetch GPIOs */ |
| 1694 |
imx_pcie->reset_gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); |
| 1695 |
if (IS_ERR(imx_pcie->reset_gpiod)) |
| 1696 |
return dev_err_probe(dev, PTR_ERR(imx_pcie->reset_gpiod), |
| 1697 |
"unable to get reset gpio\n"); |
| 1698 |
gpiod_set_consumer_name(imx_pcie->reset_gpiod, "PCIe reset"); |
| 1699 |
|
| 1700 |
/* Fetch clocks */ |
| 1701 |
imx_pcie->num_clks = devm_clk_bulk_get_all(dev, &imx_pcie->clks); |
| 1702 |
if (imx_pcie->num_clks < 0) |
| 1703 |
return dev_err_probe(dev, imx_pcie->num_clks, |
| 1704 |
"failed to get clocks\n"); |
| 1705 |
for (i = 0; i < imx_pcie->num_clks; i++) |
| 1706 |
if (strncmp(imx_pcie->clks[i].id, "extref", 6) == 0) |
| 1707 |
imx_pcie->enable_ext_refclk = true; |
| 1708 |
|
| 1709 |
if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_PHYDRV)) { |
| 1710 |
imx_pcie->phy = devm_phy_get(dev, "pcie-phy"); |
| 1711 |
if (IS_ERR(imx_pcie->phy)) |
| 1712 |
return dev_err_probe(dev, PTR_ERR(imx_pcie->phy), |
| 1713 |
"failed to get pcie phy\n"); |
| 1714 |
} |
| 1715 |
|
| 1716 |
if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_APP_RESET)) { |
| 1717 |
imx_pcie->apps_reset = devm_reset_control_get_exclusive(dev, "apps"); |
| 1718 |
if (IS_ERR(imx_pcie->apps_reset)) |
| 1719 |
return dev_err_probe(dev, PTR_ERR(imx_pcie->apps_reset), |
| 1720 |
"failed to get pcie apps reset control\n"); |
| 1721 |
} |
| 1722 |
|
| 1723 |
if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_PHY_RESET)) { |
| 1724 |
imx_pcie->pciephy_reset = devm_reset_control_get_exclusive(dev, "pciephy"); |
| 1725 |
if (IS_ERR(imx_pcie->pciephy_reset)) |
| 1726 |
return dev_err_probe(dev, PTR_ERR(imx_pcie->pciephy_reset), |
| 1727 |
"Failed to get PCIEPHY reset control\n"); |
| 1728 |
} |
| 1729 |
|
| 1730 |
switch (imx_pcie->drvdata->variant) { |
| 1731 |
case IMX8MQ: |
| 1732 |
case IMX8MQ_EP: |
| 1733 |
domain = of_get_pci_domain_nr(node); |
| 1734 |
if (domain < 0 || domain > 1) |
| 1735 |
return dev_err_probe(dev, -ENODEV, "no \"linux,pci-domain\" property in devicetree\n"); |
| 1736 |
|
| 1737 |
imx_pcie->controller_id = domain; |
| 1738 |
break; |
| 1739 |
default: |
| 1740 |
break; |
| 1741 |
} |
| 1742 |
|
| 1743 |
if (imx_pcie->drvdata->gpr) { |
| 1744 |
/* Grab GPR config register range */ |
| 1745 |
imx_pcie->iomuxc_gpr = |
| 1746 |
syscon_regmap_lookup_by_compatible(imx_pcie->drvdata->gpr); |
| 1747 |
if (IS_ERR(imx_pcie->iomuxc_gpr)) |
| 1748 |
return dev_err_probe(dev, PTR_ERR(imx_pcie->iomuxc_gpr), |
| 1749 |
"unable to find iomuxc registers\n"); |
| 1750 |
} |
| 1751 |
|
| 1752 |
if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_SERDES)) { |
| 1753 |
void __iomem *off = devm_platform_ioremap_resource_byname(pdev, "app"); |
| 1754 |
|
| 1755 |
if (IS_ERR(off)) |
| 1756 |
return dev_err_probe(dev, PTR_ERR(off), |
| 1757 |
"unable to find serdes registers\n"); |
| 1758 |
|
| 1759 |
static const struct regmap_config regmap_config = { |
| 1760 |
.reg_bits = 32, |
| 1761 |
.val_bits = 32, |
| 1762 |
.reg_stride = 4, |
| 1763 |
}; |
| 1764 |
|
| 1765 |
imx_pcie->iomuxc_gpr = devm_regmap_init_mmio(dev, off, ®map_config); |
| 1766 |
if (IS_ERR(imx_pcie->iomuxc_gpr)) |
| 1767 |
return dev_err_probe(dev, PTR_ERR(imx_pcie->iomuxc_gpr), |
| 1768 |
"unable to find iomuxc registers\n"); |
| 1769 |
} |
| 1770 |
|
| 1771 |
/* Grab PCIe PHY Tx Settings */ |
| 1772 |
if (of_property_read_u32(node, "fsl,tx-deemph-gen1", |
| 1773 |
&imx_pcie->tx_deemph_gen1)) |
| 1774 |
imx_pcie->tx_deemph_gen1 = 0; |
| 1775 |
|
| 1776 |
if (of_property_read_u32(node, "fsl,tx-deemph-gen2-3p5db", |
| 1777 |
&imx_pcie->tx_deemph_gen2_3p5db)) |
| 1778 |
imx_pcie->tx_deemph_gen2_3p5db = 0; |
| 1779 |
|
| 1780 |
if (of_property_read_u32(node, "fsl,tx-deemph-gen2-6db", |
| 1781 |
&imx_pcie->tx_deemph_gen2_6db)) |
| 1782 |
imx_pcie->tx_deemph_gen2_6db = 20; |
| 1783 |
|
| 1784 |
if (of_property_read_u32(node, "fsl,tx-swing-full", |
| 1785 |
&imx_pcie->tx_swing_full)) |
| 1786 |
imx_pcie->tx_swing_full = 127; |
| 1787 |
|
| 1788 |
if (of_property_read_u32(node, "fsl,tx-swing-low", |
| 1789 |
&imx_pcie->tx_swing_low)) |
| 1790 |
imx_pcie->tx_swing_low = 127; |
| 1791 |
|
| 1792 |
/* Limit link speed */ |
| 1793 |
pci->max_link_speed = 1; |
| 1794 |
of_property_read_u32(node, "fsl,max-link-speed", &pci->max_link_speed); |
| 1795 |
imx_pcie->supports_clkreq = of_property_read_bool(node, "supports-clkreq"); |
| 1796 |
|
| 1797 |
ret = devm_regulator_get_enable_optional(&pdev->dev, "vpcie3v3aux"); |
| 1798 |
if (ret < 0 && ret != -ENODEV) |
| 1799 |
return dev_err_probe(dev, ret, "failed to enable Vaux supply\n"); |
| 1800 |
|
| 1801 |
imx_pcie->vpcie = devm_regulator_get_optional(&pdev->dev, "vpcie"); |
| 1802 |
if (IS_ERR(imx_pcie->vpcie)) { |
| 1803 |
if (PTR_ERR(imx_pcie->vpcie) != -ENODEV) |
| 1804 |
return PTR_ERR(imx_pcie->vpcie); |
| 1805 |
imx_pcie->vpcie = NULL; |
| 1806 |
} |
| 1807 |
|
| 1808 |
imx_pcie->vph = devm_regulator_get_optional(&pdev->dev, "vph"); |
| 1809 |
if (IS_ERR(imx_pcie->vph)) { |
| 1810 |
if (PTR_ERR(imx_pcie->vph) != -ENODEV) |
| 1811 |
return PTR_ERR(imx_pcie->vph); |
| 1812 |
imx_pcie->vph = NULL; |
| 1813 |
} |
| 1814 |
|
| 1815 |
platform_set_drvdata(pdev, imx_pcie); |
| 1816 |
|
| 1817 |
ret = imx_pcie_attach_pd(dev); |
| 1818 |
if (ret) |
| 1819 |
return ret; |
| 1820 |
|
| 1821 |
pci->use_parent_dt_ranges = true; |
| 1822 |
if (imx_pcie->drvdata->mode == DW_PCIE_EP_TYPE) { |
| 1823 |
ret = imx_add_pcie_ep(imx_pcie, pdev); |
| 1824 |
if (ret < 0) |
| 1825 |
return ret; |
| 1826 |
|
| 1827 |
/* |
| 1828 |
* FIXME: Only single Device (EPF) is supported due to the |
| 1829 |
* Endpoint framework limitation. |
| 1830 |
*/ |
| 1831 |
imx_pcie_add_lut_by_rid(imx_pcie, 0); |
| 1832 |
} else { |
| 1833 |
if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_SKIP_L23_READY)) |
| 1834 |
pci->pp.skip_l23_ready = true; |
| 1835 |
if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_KEEP_MSI_CAP)) |
| 1836 |
pci->pp.keep_rp_msi_en = true; |
| 1837 |
pci->pp.use_atu_msg = true; |
| 1838 |
ret = dw_pcie_host_init(&pci->pp); |
| 1839 |
if (ret < 0) |
| 1840 |
return ret; |
| 1841 |
|
| 1842 |
if (pci_msi_enabled()) { |
| 1843 |
u8 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_MSI); |
| 1844 |
|
| 1845 |
val = dw_pcie_readw_dbi(pci, offset + PCI_MSI_FLAGS); |
| 1846 |
val |= PCI_MSI_FLAGS_ENABLE; |
| 1847 |
dw_pcie_writew_dbi(pci, offset + PCI_MSI_FLAGS, val); |
| 1848 |
} |
| 1849 |
} |
| 1850 |
|
| 1851 |
return 0; |
| 1852 |
} |
| 1853 |
|
| 1854 |
static void imx_pcie_shutdown(struct platform_device *pdev) |
| 1855 |
{ |
| 1856 |
struct imx_pcie *imx_pcie = platform_get_drvdata(pdev); |
| 1857 |
|
| 1858 |
/* bring down link, so bootloader gets clean state in case of reboot */ |
| 1859 |
imx_pcie_assert_core_reset(imx_pcie); |
| 1860 |
} |
| 1861 |
|
| 1862 |
static const struct imx_pcie_drvdata drvdata[] = { |
| 1863 |
[IMX6Q] = { |
| 1864 |
.variant = IMX6Q, |
| 1865 |
.flags = IMX_PCIE_FLAG_IMX_PHY | |
| 1866 |
IMX_PCIE_FLAG_SPEED_CHANGE_WORKAROUND | |
| 1867 |
IMX_PCIE_FLAG_BROKEN_SUSPEND | |
| 1868 |
IMX_PCIE_FLAG_SUPPORTS_SUSPEND, |
| 1869 |
.dbi_length = 0x200, |
| 1870 |
.gpr = "fsl,imx6q-iomuxc-gpr", |
| 1871 |
.ltssm_off = IOMUXC_GPR12, |
| 1872 |
.ltssm_mask = IMX6Q_GPR12_PCIE_CTL_2, |
| 1873 |
.mode_off[0] = IOMUXC_GPR12, |
| 1874 |
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, |
| 1875 |
.init_phy = imx_pcie_init_phy, |
| 1876 |
.enable_ref_clk = imx6q_pcie_enable_ref_clk, |
| 1877 |
.core_reset = imx6q_pcie_core_reset, |
| 1878 |
}, |
| 1879 |
[IMX6SX] = { |
| 1880 |
.variant = IMX6SX, |
| 1881 |
.flags = IMX_PCIE_FLAG_IMX_PHY | |
| 1882 |
IMX_PCIE_FLAG_SPEED_CHANGE_WORKAROUND | |
| 1883 |
IMX_PCIE_FLAG_SKIP_L23_READY | |
| 1884 |
IMX_PCIE_FLAG_SUPPORTS_SUSPEND, |
| 1885 |
.gpr = "fsl,imx6q-iomuxc-gpr", |
| 1886 |
.ltssm_off = IOMUXC_GPR12, |
| 1887 |
.ltssm_mask = IMX6Q_GPR12_PCIE_CTL_2, |
| 1888 |
.mode_off[0] = IOMUXC_GPR12, |
| 1889 |
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, |
| 1890 |
.init_phy = imx6sx_pcie_init_phy, |
| 1891 |
.enable_ref_clk = imx6sx_pcie_enable_ref_clk, |
| 1892 |
.core_reset = imx6sx_pcie_core_reset, |
| 1893 |
.ops = &imx_pcie_host_ops, |
| 1894 |
}, |
| 1895 |
[IMX6QP] = { |
| 1896 |
.variant = IMX6QP, |
| 1897 |
.flags = IMX_PCIE_FLAG_IMX_PHY | |
| 1898 |
IMX_PCIE_FLAG_SPEED_CHANGE_WORKAROUND | |
| 1899 |
IMX_PCIE_FLAG_SKIP_L23_READY | |
| 1900 |
IMX_PCIE_FLAG_SUPPORTS_SUSPEND, |
| 1901 |
.dbi_length = 0x200, |
| 1902 |
.gpr = "fsl,imx6q-iomuxc-gpr", |
| 1903 |
.ltssm_off = IOMUXC_GPR12, |
| 1904 |
.ltssm_mask = IMX6Q_GPR12_PCIE_CTL_2, |
| 1905 |
.mode_off[0] = IOMUXC_GPR12, |
| 1906 |
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, |
| 1907 |
.init_phy = imx_pcie_init_phy, |
| 1908 |
.enable_ref_clk = imx6q_pcie_enable_ref_clk, |
| 1909 |
.core_reset = imx6qp_pcie_core_reset, |
| 1910 |
.ops = &imx_pcie_host_ops, |
| 1911 |
}, |
| 1912 |
[IMX7D] = { |
| 1913 |
.variant = IMX7D, |
| 1914 |
.flags = IMX_PCIE_FLAG_SUPPORTS_SUSPEND | |
| 1915 |
IMX_PCIE_FLAG_KEEP_MSI_CAP | |
| 1916 |
IMX_PCIE_FLAG_HAS_APP_RESET | |
| 1917 |
IMX_PCIE_FLAG_SKIP_L23_READY | |
| 1918 |
IMX_PCIE_FLAG_HAS_PHY_RESET, |
| 1919 |
.gpr = "fsl,imx7d-iomuxc-gpr", |
| 1920 |
.mode_off[0] = IOMUXC_GPR12, |
| 1921 |
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, |
| 1922 |
.enable_ref_clk = imx7d_pcie_enable_ref_clk, |
| 1923 |
.core_reset = imx7d_pcie_core_reset, |
| 1924 |
}, |
| 1925 |
[IMX8MQ] = { |
| 1926 |
.variant = IMX8MQ, |
| 1927 |
.flags = IMX_PCIE_FLAG_HAS_APP_RESET | |
| 1928 |
IMX_PCIE_FLAG_KEEP_MSI_CAP | |
| 1929 |
IMX_PCIE_FLAG_HAS_PHY_RESET | |
| 1930 |
IMX_PCIE_FLAG_SUPPORTS_SUSPEND, |
| 1931 |
.gpr = "fsl,imx8mq-iomuxc-gpr", |
| 1932 |
.mode_off[0] = IOMUXC_GPR12, |
| 1933 |
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, |
| 1934 |
.mode_off[1] = IOMUXC_GPR12, |
| 1935 |
.mode_mask[1] = IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE, |
| 1936 |
.init_phy = imx8mq_pcie_init_phy, |
| 1937 |
.enable_ref_clk = imx8mm_pcie_enable_ref_clk, |
| 1938 |
.clr_clkreq_override = imx8mm_pcie_clr_clkreq_override, |
| 1939 |
}, |
| 1940 |
[IMX8MM] = { |
| 1941 |
.variant = IMX8MM, |
| 1942 |
.flags = IMX_PCIE_FLAG_SUPPORTS_SUSPEND | |
| 1943 |
IMX_PCIE_FLAG_KEEP_MSI_CAP | |
| 1944 |
IMX_PCIE_FLAG_HAS_PHYDRV | |
| 1945 |
IMX_PCIE_FLAG_HAS_APP_RESET, |
| 1946 |
.gpr = "fsl,imx8mm-iomuxc-gpr", |
| 1947 |
.mode_off[0] = IOMUXC_GPR12, |
| 1948 |
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, |
| 1949 |
.enable_ref_clk = imx8mm_pcie_enable_ref_clk, |
| 1950 |
.clr_clkreq_override = imx8mm_pcie_clr_clkreq_override, |
| 1951 |
}, |
| 1952 |
[IMX8MP] = { |
| 1953 |
.variant = IMX8MP, |
| 1954 |
.flags = IMX_PCIE_FLAG_SUPPORTS_SUSPEND | |
| 1955 |
IMX_PCIE_FLAG_HAS_PHYDRV | |
| 1956 |
IMX_PCIE_FLAG_HAS_APP_RESET, |
| 1957 |
.gpr = "fsl,imx8mp-iomuxc-gpr", |
| 1958 |
.mode_off[0] = IOMUXC_GPR12, |
| 1959 |
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, |
| 1960 |
.enable_ref_clk = imx8mm_pcie_enable_ref_clk, |
| 1961 |
.clr_clkreq_override = imx8mm_pcie_clr_clkreq_override, |
| 1962 |
}, |
| 1963 |
[IMX8Q] = { |
| 1964 |
.variant = IMX8Q, |
| 1965 |
.flags = IMX_PCIE_FLAG_HAS_PHYDRV | |
| 1966 |
IMX_PCIE_FLAG_CPU_ADDR_FIXUP | |
| 1967 |
IMX_PCIE_FLAG_SUPPORTS_SUSPEND, |
| 1968 |
}, |
| 1969 |
[IMX95] = { |
| 1970 |
.variant = IMX95, |
| 1971 |
.flags = IMX_PCIE_FLAG_HAS_SERDES | |
| 1972 |
IMX_PCIE_FLAG_HAS_LUT | |
| 1973 |
IMX_PCIE_FLAG_8GT_ECN_ERR051586 | |
| 1974 |
IMX_PCIE_FLAG_SUPPORTS_SUSPEND, |
| 1975 |
.ltssm_off = IMX95_PE0_GEN_CTRL_3, |
| 1976 |
.ltssm_mask = IMX95_PCIE_LTSSM_EN, |
| 1977 |
.mode_off[0] = IMX95_PE0_GEN_CTRL_1, |
| 1978 |
.mode_mask[0] = IMX95_PCIE_DEVICE_TYPE, |
| 1979 |
.core_reset = imx95_pcie_core_reset, |
| 1980 |
.init_phy = imx95_pcie_init_phy, |
| 1981 |
.wait_pll_lock = imx95_pcie_wait_for_phy_pll_lock, |
| 1982 |
.enable_ref_clk = imx95_pcie_enable_ref_clk, |
| 1983 |
.clr_clkreq_override = imx95_pcie_clr_clkreq_override, |
| 1984 |
}, |
| 1985 |
[IMX8MQ_EP] = { |
| 1986 |
.variant = IMX8MQ_EP, |
| 1987 |
.flags = IMX_PCIE_FLAG_HAS_APP_RESET | |
| 1988 |
IMX_PCIE_FLAG_HAS_PHY_RESET, |
| 1989 |
.mode = DW_PCIE_EP_TYPE, |
| 1990 |
.gpr = "fsl,imx8mq-iomuxc-gpr", |
| 1991 |
.mode_off[0] = IOMUXC_GPR12, |
| 1992 |
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, |
| 1993 |
.mode_off[1] = IOMUXC_GPR12, |
| 1994 |
.mode_mask[1] = IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE, |
| 1995 |
.epc_features = &imx8q_pcie_epc_features, |
| 1996 |
.init_phy = imx8mq_pcie_init_phy, |
| 1997 |
.enable_ref_clk = imx8mm_pcie_enable_ref_clk, |
| 1998 |
}, |
| 1999 |
[IMX8MM_EP] = { |
| 2000 |
.variant = IMX8MM_EP, |
| 2001 |
.flags = IMX_PCIE_FLAG_HAS_APP_RESET | |
| 2002 |
IMX_PCIE_FLAG_HAS_PHYDRV, |
| 2003 |
.mode = DW_PCIE_EP_TYPE, |
| 2004 |
.gpr = "fsl,imx8mm-iomuxc-gpr", |
| 2005 |
.mode_off[0] = IOMUXC_GPR12, |
| 2006 |
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, |
| 2007 |
.epc_features = &imx8m_pcie_epc_features, |
| 2008 |
.enable_ref_clk = imx8mm_pcie_enable_ref_clk, |
| 2009 |
}, |
| 2010 |
[IMX8MP_EP] = { |
| 2011 |
.variant = IMX8MP_EP, |
| 2012 |
.flags = IMX_PCIE_FLAG_HAS_APP_RESET | |
| 2013 |
IMX_PCIE_FLAG_HAS_PHYDRV, |
| 2014 |
.mode = DW_PCIE_EP_TYPE, |
| 2015 |
.gpr = "fsl,imx8mp-iomuxc-gpr", |
| 2016 |
.mode_off[0] = IOMUXC_GPR12, |
| 2017 |
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, |
| 2018 |
.epc_features = &imx8m_pcie_epc_features, |
| 2019 |
.enable_ref_clk = imx8mm_pcie_enable_ref_clk, |
| 2020 |
}, |
| 2021 |
[IMX8Q_EP] = { |
| 2022 |
.variant = IMX8Q_EP, |
| 2023 |
.flags = IMX_PCIE_FLAG_HAS_PHYDRV, |
| 2024 |
.mode = DW_PCIE_EP_TYPE, |
| 2025 |
.epc_features = &imx8q_pcie_epc_features, |
| 2026 |
}, |
| 2027 |
[IMX95_EP] = { |
| 2028 |
.variant = IMX95_EP, |
| 2029 |
.flags = IMX_PCIE_FLAG_HAS_SERDES | |
| 2030 |
IMX_PCIE_FLAG_8GT_ECN_ERR051586 | |
| 2031 |
IMX_PCIE_FLAG_SUPPORT_64BIT, |
| 2032 |
.ltssm_off = IMX95_PE0_GEN_CTRL_3, |
| 2033 |
.ltssm_mask = IMX95_PCIE_LTSSM_EN, |
| 2034 |
.mode_off[0] = IMX95_PE0_GEN_CTRL_1, |
| 2035 |
.mode_mask[0] = IMX95_PCIE_DEVICE_TYPE, |
| 2036 |
.init_phy = imx95_pcie_init_phy, |
| 2037 |
.core_reset = imx95_pcie_core_reset, |
| 2038 |
.wait_pll_lock = imx95_pcie_wait_for_phy_pll_lock, |
| 2039 |
.epc_features = &imx95_pcie_epc_features, |
| 2040 |
.enable_ref_clk = imx95_pcie_enable_ref_clk, |
| 2041 |
.mode = DW_PCIE_EP_TYPE, |
| 2042 |
}, |
| 2043 |
}; |
| 2044 |
|
| 2045 |
static const struct of_device_id imx_pcie_of_match[] = { |
| 2046 |
{ .compatible = "fsl,imx6q-pcie", .data = &drvdata[IMX6Q], }, |
| 2047 |
{ .compatible = "fsl,imx6sx-pcie", .data = &drvdata[IMX6SX], }, |
| 2048 |
{ .compatible = "fsl,imx6qp-pcie", .data = &drvdata[IMX6QP], }, |
| 2049 |
{ .compatible = "fsl,imx7d-pcie", .data = &drvdata[IMX7D], }, |
| 2050 |
{ .compatible = "fsl,imx8mq-pcie", .data = &drvdata[IMX8MQ], }, |
| 2051 |
{ .compatible = "fsl,imx8mm-pcie", .data = &drvdata[IMX8MM], }, |
| 2052 |
{ .compatible = "fsl,imx8mp-pcie", .data = &drvdata[IMX8MP], }, |
| 2053 |
{ .compatible = "fsl,imx8q-pcie", .data = &drvdata[IMX8Q], }, |
| 2054 |
{ .compatible = "fsl,imx95-pcie", .data = &drvdata[IMX95], }, |
| 2055 |
{ .compatible = "fsl,imx8mq-pcie-ep", .data = &drvdata[IMX8MQ_EP], }, |
| 2056 |
{ .compatible = "fsl,imx8mm-pcie-ep", .data = &drvdata[IMX8MM_EP], }, |
| 2057 |
{ .compatible = "fsl,imx8mp-pcie-ep", .data = &drvdata[IMX8MP_EP], }, |
| 2058 |
{ .compatible = "fsl,imx8q-pcie-ep", .data = &drvdata[IMX8Q_EP], }, |
| 2059 |
{ .compatible = "fsl,imx95-pcie-ep", .data = &drvdata[IMX95_EP], }, |
| 2060 |
{}, |
| 2061 |
}; |
| 2062 |
|
| 2063 |
static struct platform_driver imx_pcie_driver = { |
| 2064 |
.driver = { |
| 2065 |
.name = "imx6q-pcie", |
| 2066 |
.of_match_table = imx_pcie_of_match, |
| 2067 |
.suppress_bind_attrs = true, |
| 2068 |
.pm = &imx_pcie_pm_ops, |
| 2069 |
.probe_type = PROBE_PREFER_ASYNCHRONOUS, |
| 2070 |
}, |
| 2071 |
.probe = imx_pcie_probe, |
| 2072 |
.shutdown = imx_pcie_shutdown, |
| 2073 |
}; |
| 2074 |
|
| 2075 |
static void imx_pcie_quirk(struct pci_dev *dev) |
| 2076 |
{ |
| 2077 |
struct pci_bus *bus = dev->bus; |
| 2078 |
struct dw_pcie_rp *pp = bus->sysdata; |
| 2079 |
|
| 2080 |
/* Bus parent is the PCI bridge, its parent is this platform driver */ |
| 2081 |
if (!bus->dev.parent || !bus->dev.parent->parent) |
| 2082 |
return; |
| 2083 |
|
| 2084 |
/* Make sure we only quirk devices associated with this driver */ |
| 2085 |
if (bus->dev.parent->parent->driver != &imx_pcie_driver.driver) |
| 2086 |
return; |
| 2087 |
|
| 2088 |
if (pci_is_root_bus(bus)) { |
| 2089 |
struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
| 2090 |
struct imx_pcie *imx_pcie = to_imx_pcie(pci); |
| 2091 |
|
| 2092 |
/* |
| 2093 |
* Limit config length to avoid the kernel reading beyond |
| 2094 |
* the register set and causing an abort on i.MX 6Quad |
| 2095 |
*/ |
| 2096 |
if (imx_pcie->drvdata->dbi_length) { |
| 2097 |
dev->cfg_size = imx_pcie->drvdata->dbi_length; |
| 2098 |
dev_info(&dev->dev, "Limiting cfg_size to %d\n", |
| 2099 |
dev->cfg_size); |
| 2100 |
} |
| 2101 |
} |
| 2102 |
} |
| 2103 |
DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_SYNOPSYS, 0xabcd, |
| 2104 |
PCI_CLASS_BRIDGE_PCI, 8, imx_pcie_quirk); |
| 2105 |
|
| 2106 |
static int __init imx_pcie_init(void) |
| 2107 |
{ |
| 2108 |
#ifdef CONFIG_ARM |
| 2109 |
struct device_node *np; |
| 2110 |
|
| 2111 |
np = of_find_matching_node(NULL, imx_pcie_of_match); |
| 2112 |
if (!np) |
| 2113 |
return -ENODEV; |
| 2114 |
of_node_put(np); |
| 2115 |
|
| 2116 |
/* |
| 2117 |
* Since probe() can be deferred we need to make sure that |
| 2118 |
* hook_fault_code is not called after __init memory is freed |
| 2119 |
* by kernel and since imx6q_pcie_abort_handler() is a no-op, |
| 2120 |
* we can install the handler here without risking it |
| 2121 |
* accessing some uninitialized driver state. |
| 2122 |
*/ |
| 2123 |
hook_fault_code(8, imx6q_pcie_abort_handler, SIGBUS, 0, |
| 2124 |
"external abort on non-linefetch"); |
| 2125 |
#endif |
| 2126 |
|
| 2127 |
return platform_driver_register(&imx_pcie_driver); |
| 2128 |
} |
| 2129 |
device_initcall(imx_pcie_init); |