diff options
author | Bjorn Helgaas <bhelgaas@google.com> | 2019-05-13 19:34:39 -0400 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2019-05-13 19:34:39 -0400 |
commit | 5349abcf8e5f09a178910225a90d4a0329f82a1f (patch) | |
tree | 69e4f52c272f5e8dbab92158fa3c673161b5a009 | |
parent | 29fa3bbd6c205bb12d1046243af7b9160df73a90 (diff) | |
parent | 87cb312777b5dc5eece8e1c58d4e0040eeea39fa (diff) |
Merge branch 'remotes/lorenzo/pci/imx'
- Simplify imx7d_pcie_wait_for_phy_pll_lock() by using
regmap_read_poll_timeout() (Andrey Smirnov)
- Drop imx6_pcie_wait_for_link() in favor of the more generic
dw_pcie_wait_for_link() (Andrey Smirnov)
- Return -ETIMEDOUT instead of -EINVAL from
imx6_pcie_wait_for_speed_change() (Andrey Smirnov)
- Remove unused PCIE_PL_PFLR_* constants from imx6 (Andrey Smirnov)
- Use shared PHY debug register definitions in imx6 (Andrey Smirnov)
- Use BIT() in imx6 (Andrey Smirnov)
- Simplify imx6 PHY bit operations (Andrey Smirnov)
- Simplify imx6 pcie_phy_poll_ack() (Andrey Smirnov)
- Use data types that match actual imx6 PHY register width (Andrey
Smirnov)
- Mark imx6 suspend support with drvdata flags instead of checking
variants (Andrey Smirnov)
- Sleep instead of delay in imx6_pcie_enable_ref_clk() (Andrey Smirnov)
* remotes/lorenzo/pci/imx:
PCI: imx6: Use usleep_range() in imx6_pcie_enable_ref_clk()
PCI: imx6: Use flags to indicate support for suspend
PCI: imx6: Restrict PHY register data to 16-bit
PCI: imx6: Simplify pcie_phy_poll_ack()
PCI: imx6: Simplify bit operations in PHY functions
PCI: imx6: Make use of BIT() in constant definitions
PCI: dwc: imx6: Share PHY debug register definitions
PCI: imx6: Remove PCIE_PL_PFLR_* constants
PCI: imx6: Return -ETIMEOUT from imx6_pcie_wait_for_speed_change()
PCI: imx6: Drop imx6_pcie_wait_for_link()
PCI: imx6: Simplify imx7d_pcie_wait_for_phy_pll_lock()
-rw-r--r-- | drivers/pci/controller/dwc/pci-imx6.c | 143 | ||||
-rw-r--r-- | drivers/pci/controller/dwc/pcie-designware.c | 12 | ||||
-rw-r--r-- | drivers/pci/controller/dwc/pcie-designware.h | 3 |
3 files changed, 62 insertions, 96 deletions
diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 2eb39d5de4f6..9b5cb5b70389 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c | |||
@@ -52,6 +52,7 @@ enum imx6_pcie_variants { | |||
52 | 52 | ||
53 | #define IMX6_PCIE_FLAG_IMX6_PHY BIT(0) | 53 | #define IMX6_PCIE_FLAG_IMX6_PHY BIT(0) |
54 | #define IMX6_PCIE_FLAG_IMX6_SPEED_CHANGE BIT(1) | 54 | #define IMX6_PCIE_FLAG_IMX6_SPEED_CHANGE BIT(1) |
55 | #define IMX6_PCIE_FLAG_SUPPORTS_SUSPEND BIT(2) | ||
55 | 56 | ||
56 | struct imx6_pcie_drvdata { | 57 | struct imx6_pcie_drvdata { |
57 | enum imx6_pcie_variants variant; | 58 | enum imx6_pcie_variants variant; |
@@ -89,9 +90,8 @@ struct imx6_pcie { | |||
89 | }; | 90 | }; |
90 | 91 | ||
91 | /* Parameters for the waiting for PCIe PHY PLL to lock on i.MX7 */ | 92 | /* Parameters for the waiting for PCIe PHY PLL to lock on i.MX7 */ |
92 | #define PHY_PLL_LOCK_WAIT_MAX_RETRIES 2000 | ||
93 | #define PHY_PLL_LOCK_WAIT_USLEEP_MIN 50 | ||
94 | #define PHY_PLL_LOCK_WAIT_USLEEP_MAX 200 | 93 | #define PHY_PLL_LOCK_WAIT_USLEEP_MAX 200 |
94 | #define PHY_PLL_LOCK_WAIT_TIMEOUT (2000 * PHY_PLL_LOCK_WAIT_USLEEP_MAX) | ||
95 | 95 | ||
96 | /* PCIe Root Complex registers (memory-mapped) */ | 96 | /* PCIe Root Complex registers (memory-mapped) */ |
97 | #define PCIE_RC_IMX6_MSI_CAP 0x50 | 97 | #define PCIE_RC_IMX6_MSI_CAP 0x50 |
@@ -104,34 +104,29 @@ struct imx6_pcie { | |||
104 | 104 | ||
105 | /* PCIe Port Logic registers (memory-mapped) */ | 105 | /* PCIe Port Logic registers (memory-mapped) */ |
106 | #define PL_OFFSET 0x700 | 106 | #define PL_OFFSET 0x700 |
107 | #define PCIE_PL_PFLR (PL_OFFSET + 0x08) | ||
108 | #define PCIE_PL_PFLR_LINK_STATE_MASK (0x3f << 16) | ||
109 | #define PCIE_PL_PFLR_FORCE_LINK (1 << 15) | ||
110 | #define PCIE_PHY_DEBUG_R0 (PL_OFFSET + 0x28) | ||
111 | #define PCIE_PHY_DEBUG_R1 (PL_OFFSET + 0x2c) | ||
112 | 107 | ||
113 | #define PCIE_PHY_CTRL (PL_OFFSET + 0x114) | 108 | #define PCIE_PHY_CTRL (PL_OFFSET + 0x114) |
114 | #define PCIE_PHY_CTRL_DATA_LOC 0 | 109 | #define PCIE_PHY_CTRL_DATA(x) FIELD_PREP(GENMASK(15, 0), (x)) |
115 | #define PCIE_PHY_CTRL_CAP_ADR_LOC 16 | 110 | #define PCIE_PHY_CTRL_CAP_ADR BIT(16) |
116 | #define PCIE_PHY_CTRL_CAP_DAT_LOC 17 | 111 | #define PCIE_PHY_CTRL_CAP_DAT BIT(17) |
117 | #define PCIE_PHY_CTRL_WR_LOC 18 | 112 | #define PCIE_PHY_CTRL_WR BIT(18) |
118 | #define PCIE_PHY_CTRL_RD_LOC 19 | 113 | #define PCIE_PHY_CTRL_RD BIT(19) |
119 | 114 | ||
120 | #define PCIE_PHY_STAT (PL_OFFSET + 0x110) | 115 | #define PCIE_PHY_STAT (PL_OFFSET + 0x110) |
121 | #define PCIE_PHY_STAT_ACK_LOC 16 | 116 | #define PCIE_PHY_STAT_ACK BIT(16) |
122 | 117 | ||
123 | #define PCIE_LINK_WIDTH_SPEED_CONTROL 0x80C | 118 | #define PCIE_LINK_WIDTH_SPEED_CONTROL 0x80C |
124 | 119 | ||
125 | /* PHY registers (not memory-mapped) */ | 120 | /* PHY registers (not memory-mapped) */ |
126 | #define PCIE_PHY_ATEOVRD 0x10 | 121 | #define PCIE_PHY_ATEOVRD 0x10 |
127 | #define PCIE_PHY_ATEOVRD_EN (0x1 << 2) | 122 | #define PCIE_PHY_ATEOVRD_EN BIT(2) |
128 | #define PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT 0 | 123 | #define PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT 0 |
129 | #define PCIE_PHY_ATEOVRD_REF_CLKDIV_MASK 0x1 | 124 | #define PCIE_PHY_ATEOVRD_REF_CLKDIV_MASK 0x1 |
130 | 125 | ||
131 | #define PCIE_PHY_MPLL_OVRD_IN_LO 0x11 | 126 | #define PCIE_PHY_MPLL_OVRD_IN_LO 0x11 |
132 | #define PCIE_PHY_MPLL_MULTIPLIER_SHIFT 2 | 127 | #define PCIE_PHY_MPLL_MULTIPLIER_SHIFT 2 |
133 | #define PCIE_PHY_MPLL_MULTIPLIER_MASK 0x7f | 128 | #define PCIE_PHY_MPLL_MULTIPLIER_MASK 0x7f |
134 | #define PCIE_PHY_MPLL_MULTIPLIER_OVRD (0x1 << 9) | 129 | #define PCIE_PHY_MPLL_MULTIPLIER_OVRD BIT(9) |
135 | 130 | ||
136 | #define PCIE_PHY_RX_ASIC_OUT 0x100D | 131 | #define PCIE_PHY_RX_ASIC_OUT 0x100D |
137 | #define PCIE_PHY_RX_ASIC_OUT_VALID (1 << 0) | 132 | #define PCIE_PHY_RX_ASIC_OUT_VALID (1 << 0) |
@@ -154,19 +149,19 @@ struct imx6_pcie { | |||
154 | #define PCIE_PHY_CMN_REG26_ATT_MODE 0xBC | 149 | #define PCIE_PHY_CMN_REG26_ATT_MODE 0xBC |
155 | 150 | ||
156 | #define PHY_RX_OVRD_IN_LO 0x1005 | 151 | #define PHY_RX_OVRD_IN_LO 0x1005 |
157 | #define PHY_RX_OVRD_IN_LO_RX_DATA_EN (1 << 5) | 152 | #define PHY_RX_OVRD_IN_LO_RX_DATA_EN BIT(5) |
158 | #define PHY_RX_OVRD_IN_LO_RX_PLL_EN (1 << 3) | 153 | #define PHY_RX_OVRD_IN_LO_RX_PLL_EN BIT(3) |
159 | 154 | ||
160 | static int pcie_phy_poll_ack(struct imx6_pcie *imx6_pcie, int exp_val) | 155 | static int pcie_phy_poll_ack(struct imx6_pcie *imx6_pcie, bool exp_val) |
161 | { | 156 | { |
162 | struct dw_pcie *pci = imx6_pcie->pci; | 157 | struct dw_pcie *pci = imx6_pcie->pci; |
163 | u32 val; | 158 | bool val; |
164 | u32 max_iterations = 10; | 159 | u32 max_iterations = 10; |
165 | u32 wait_counter = 0; | 160 | u32 wait_counter = 0; |
166 | 161 | ||
167 | do { | 162 | do { |
168 | val = dw_pcie_readl_dbi(pci, PCIE_PHY_STAT); | 163 | val = dw_pcie_readl_dbi(pci, PCIE_PHY_STAT) & |
169 | val = (val >> PCIE_PHY_STAT_ACK_LOC) & 0x1; | 164 | PCIE_PHY_STAT_ACK; |
170 | wait_counter++; | 165 | wait_counter++; |
171 | 166 | ||
172 | if (val == exp_val) | 167 | if (val == exp_val) |
@@ -184,27 +179,27 @@ static int pcie_phy_wait_ack(struct imx6_pcie *imx6_pcie, int addr) | |||
184 | u32 val; | 179 | u32 val; |
185 | int ret; | 180 | int ret; |
186 | 181 | ||
187 | val = addr << PCIE_PHY_CTRL_DATA_LOC; | 182 | val = PCIE_PHY_CTRL_DATA(addr); |
188 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val); | 183 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val); |
189 | 184 | ||
190 | val |= (0x1 << PCIE_PHY_CTRL_CAP_ADR_LOC); | 185 | val |= PCIE_PHY_CTRL_CAP_ADR; |
191 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val); | 186 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val); |
192 | 187 | ||
193 | ret = pcie_phy_poll_ack(imx6_pcie, 1); | 188 | ret = pcie_phy_poll_ack(imx6_pcie, true); |
194 | if (ret) | 189 | if (ret) |
195 | return ret; | 190 | return ret; |
196 | 191 | ||
197 | val = addr << PCIE_PHY_CTRL_DATA_LOC; | 192 | val = PCIE_PHY_CTRL_DATA(addr); |
198 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val); | 193 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val); |
199 | 194 | ||
200 | return pcie_phy_poll_ack(imx6_pcie, 0); | 195 | return pcie_phy_poll_ack(imx6_pcie, false); |
201 | } | 196 | } |
202 | 197 | ||
203 | /* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */ | 198 | /* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */ |
204 | static int pcie_phy_read(struct imx6_pcie *imx6_pcie, int addr, int *data) | 199 | static int pcie_phy_read(struct imx6_pcie *imx6_pcie, int addr, u16 *data) |
205 | { | 200 | { |
206 | struct dw_pcie *pci = imx6_pcie->pci; | 201 | struct dw_pcie *pci = imx6_pcie->pci; |
207 | u32 val, phy_ctl; | 202 | u32 phy_ctl; |
208 | int ret; | 203 | int ret; |
209 | 204 | ||
210 | ret = pcie_phy_wait_ack(imx6_pcie, addr); | 205 | ret = pcie_phy_wait_ack(imx6_pcie, addr); |
@@ -212,23 +207,22 @@ static int pcie_phy_read(struct imx6_pcie *imx6_pcie, int addr, int *data) | |||
212 | return ret; | 207 | return ret; |
213 | 208 | ||
214 | /* assert Read signal */ | 209 | /* assert Read signal */ |
215 | phy_ctl = 0x1 << PCIE_PHY_CTRL_RD_LOC; | 210 | phy_ctl = PCIE_PHY_CTRL_RD; |
216 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, phy_ctl); | 211 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, phy_ctl); |
217 | 212 | ||
218 | ret = pcie_phy_poll_ack(imx6_pcie, 1); | 213 | ret = pcie_phy_poll_ack(imx6_pcie, true); |
219 | if (ret) | 214 | if (ret) |
220 | return ret; | 215 | return ret; |
221 | 216 | ||
222 | val = dw_pcie_readl_dbi(pci, PCIE_PHY_STAT); | 217 | *data = dw_pcie_readl_dbi(pci, PCIE_PHY_STAT); |
223 | *data = val & 0xffff; | ||
224 | 218 | ||
225 | /* deassert Read signal */ | 219 | /* deassert Read signal */ |
226 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, 0x00); | 220 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, 0x00); |
227 | 221 | ||
228 | return pcie_phy_poll_ack(imx6_pcie, 0); | 222 | return pcie_phy_poll_ack(imx6_pcie, false); |
229 | } | 223 | } |
230 | 224 | ||
231 | static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, int data) | 225 | static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, u16 data) |
232 | { | 226 | { |
233 | struct dw_pcie *pci = imx6_pcie->pci; | 227 | struct dw_pcie *pci = imx6_pcie->pci; |
234 | u32 var; | 228 | u32 var; |
@@ -240,41 +234,41 @@ static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, int data) | |||
240 | if (ret) | 234 | if (ret) |
241 | return ret; | 235 | return ret; |
242 | 236 | ||
243 | var = data << PCIE_PHY_CTRL_DATA_LOC; | 237 | var = PCIE_PHY_CTRL_DATA(data); |
244 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); | 238 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
245 | 239 | ||
246 | /* capture data */ | 240 | /* capture data */ |
247 | var |= (0x1 << PCIE_PHY_CTRL_CAP_DAT_LOC); | 241 | var |= PCIE_PHY_CTRL_CAP_DAT; |
248 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); | 242 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
249 | 243 | ||
250 | ret = pcie_phy_poll_ack(imx6_pcie, 1); | 244 | ret = pcie_phy_poll_ack(imx6_pcie, true); |
251 | if (ret) | 245 | if (ret) |
252 | return ret; | 246 | return ret; |
253 | 247 | ||
254 | /* deassert cap data */ | 248 | /* deassert cap data */ |
255 | var = data << PCIE_PHY_CTRL_DATA_LOC; | 249 | var = PCIE_PHY_CTRL_DATA(data); |
256 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); | 250 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
257 | 251 | ||
258 | /* wait for ack de-assertion */ | 252 | /* wait for ack de-assertion */ |
259 | ret = pcie_phy_poll_ack(imx6_pcie, 0); | 253 | ret = pcie_phy_poll_ack(imx6_pcie, false); |
260 | if (ret) | 254 | if (ret) |
261 | return ret; | 255 | return ret; |
262 | 256 | ||
263 | /* assert wr signal */ | 257 | /* assert wr signal */ |
264 | var = 0x1 << PCIE_PHY_CTRL_WR_LOC; | 258 | var = PCIE_PHY_CTRL_WR; |
265 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); | 259 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
266 | 260 | ||
267 | /* wait for ack */ | 261 | /* wait for ack */ |
268 | ret = pcie_phy_poll_ack(imx6_pcie, 1); | 262 | ret = pcie_phy_poll_ack(imx6_pcie, true); |
269 | if (ret) | 263 | if (ret) |
270 | return ret; | 264 | return ret; |
271 | 265 | ||
272 | /* deassert wr signal */ | 266 | /* deassert wr signal */ |
273 | var = data << PCIE_PHY_CTRL_DATA_LOC; | 267 | var = PCIE_PHY_CTRL_DATA(data); |
274 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); | 268 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
275 | 269 | ||
276 | /* wait for ack de-assertion */ | 270 | /* wait for ack de-assertion */ |
277 | ret = pcie_phy_poll_ack(imx6_pcie, 0); | 271 | ret = pcie_phy_poll_ack(imx6_pcie, false); |
278 | if (ret) | 272 | if (ret) |
279 | return ret; | 273 | return ret; |
280 | 274 | ||
@@ -285,7 +279,7 @@ static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, int data) | |||
285 | 279 | ||
286 | static void imx6_pcie_reset_phy(struct imx6_pcie *imx6_pcie) | 280 | static void imx6_pcie_reset_phy(struct imx6_pcie *imx6_pcie) |
287 | { | 281 | { |
288 | u32 tmp; | 282 | u16 tmp; |
289 | 283 | ||
290 | if (!(imx6_pcie->drvdata->flags & IMX6_PCIE_FLAG_IMX6_PHY)) | 284 | if (!(imx6_pcie->drvdata->flags & IMX6_PCIE_FLAG_IMX6_PHY)) |
291 | return; | 285 | return; |
@@ -455,7 +449,7 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie) | |||
455 | * reset time is too short, cannot meet the requirement. | 449 | * reset time is too short, cannot meet the requirement. |
456 | * add one ~10us delay here. | 450 | * add one ~10us delay here. |
457 | */ | 451 | */ |
458 | udelay(10); | 452 | usleep_range(10, 100); |
459 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, | 453 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, |
460 | IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16); | 454 | IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16); |
461 | break; | 455 | break; |
@@ -488,20 +482,14 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie) | |||
488 | static void imx7d_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie) | 482 | static void imx7d_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie) |
489 | { | 483 | { |
490 | u32 val; | 484 | u32 val; |
491 | unsigned int retries; | ||
492 | struct device *dev = imx6_pcie->pci->dev; | 485 | struct device *dev = imx6_pcie->pci->dev; |
493 | 486 | ||
494 | for (retries = 0; retries < PHY_PLL_LOCK_WAIT_MAX_RETRIES; retries++) { | 487 | if (regmap_read_poll_timeout(imx6_pcie->iomuxc_gpr, |
495 | regmap_read(imx6_pcie->iomuxc_gpr, IOMUXC_GPR22, &val); | 488 | IOMUXC_GPR22, val, |
496 | 489 | val & IMX7D_GPR22_PCIE_PHY_PLL_LOCKED, | |
497 | if (val & IMX7D_GPR22_PCIE_PHY_PLL_LOCKED) | 490 | PHY_PLL_LOCK_WAIT_USLEEP_MAX, |
498 | return; | 491 | PHY_PLL_LOCK_WAIT_TIMEOUT)) |
499 | 492 | dev_err(dev, "PCIe PLL lock timeout\n"); | |
500 | usleep_range(PHY_PLL_LOCK_WAIT_USLEEP_MIN, | ||
501 | PHY_PLL_LOCK_WAIT_USLEEP_MAX); | ||
502 | } | ||
503 | |||
504 | dev_err(dev, "PCIe PLL lock timeout\n"); | ||
505 | } | 493 | } |
506 | 494 | ||
507 | static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) | 495 | static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) |
@@ -687,7 +675,7 @@ static int imx6_setup_phy_mpll(struct imx6_pcie *imx6_pcie) | |||
687 | { | 675 | { |
688 | unsigned long phy_rate = clk_get_rate(imx6_pcie->pcie_phy); | 676 | unsigned long phy_rate = clk_get_rate(imx6_pcie->pcie_phy); |
689 | int mult, div; | 677 | int mult, div; |
690 | u32 val; | 678 | u16 val; |
691 | 679 | ||
692 | if (!(imx6_pcie->drvdata->flags & IMX6_PCIE_FLAG_IMX6_PHY)) | 680 | if (!(imx6_pcie->drvdata->flags & IMX6_PCIE_FLAG_IMX6_PHY)) |
693 | return 0; | 681 | return 0; |
@@ -730,21 +718,6 @@ static int imx6_setup_phy_mpll(struct imx6_pcie *imx6_pcie) | |||
730 | return 0; | 718 | return 0; |
731 | } | 719 | } |
732 | 720 | ||
733 | static int imx6_pcie_wait_for_link(struct imx6_pcie *imx6_pcie) | ||
734 | { | ||
735 | struct dw_pcie *pci = imx6_pcie->pci; | ||
736 | struct device *dev = pci->dev; | ||
737 | |||
738 | /* check if the link is up or not */ | ||
739 | if (!dw_pcie_wait_for_link(pci)) | ||
740 | return 0; | ||
741 | |||
742 | dev_dbg(dev, "DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n", | ||
743 | dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R0), | ||
744 | dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R1)); | ||
745 | return -ETIMEDOUT; | ||
746 | } | ||
747 | |||
748 | static int imx6_pcie_wait_for_speed_change(struct imx6_pcie *imx6_pcie) | 721 | static int imx6_pcie_wait_for_speed_change(struct imx6_pcie *imx6_pcie) |
749 | { | 722 | { |
750 | struct dw_pcie *pci = imx6_pcie->pci; | 723 | struct dw_pcie *pci = imx6_pcie->pci; |
@@ -761,7 +734,7 @@ static int imx6_pcie_wait_for_speed_change(struct imx6_pcie *imx6_pcie) | |||
761 | } | 734 | } |
762 | 735 | ||
763 | dev_err(dev, "Speed change timeout\n"); | 736 | dev_err(dev, "Speed change timeout\n"); |
764 | return -EINVAL; | 737 | return -ETIMEDOUT; |
765 | } | 738 | } |
766 | 739 | ||
767 | static void imx6_pcie_ltssm_enable(struct device *dev) | 740 | static void imx6_pcie_ltssm_enable(struct device *dev) |
@@ -803,7 +776,7 @@ static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie) | |||
803 | /* Start LTSSM. */ | 776 | /* Start LTSSM. */ |
804 | imx6_pcie_ltssm_enable(dev); | 777 | imx6_pcie_ltssm_enable(dev); |
805 | 778 | ||
806 | ret = imx6_pcie_wait_for_link(imx6_pcie); | 779 | ret = dw_pcie_wait_for_link(pci); |
807 | if (ret) | 780 | if (ret) |
808 | goto err_reset_phy; | 781 | goto err_reset_phy; |
809 | 782 | ||
@@ -841,7 +814,7 @@ static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie) | |||
841 | } | 814 | } |
842 | 815 | ||
843 | /* Make sure link training is finished as well! */ | 816 | /* Make sure link training is finished as well! */ |
844 | ret = imx6_pcie_wait_for_link(imx6_pcie); | 817 | ret = dw_pcie_wait_for_link(pci); |
845 | if (ret) { | 818 | if (ret) { |
846 | dev_err(dev, "Failed to bring link up!\n"); | 819 | dev_err(dev, "Failed to bring link up!\n"); |
847 | goto err_reset_phy; | 820 | goto err_reset_phy; |
@@ -856,8 +829,8 @@ static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie) | |||
856 | 829 | ||
857 | err_reset_phy: | 830 | err_reset_phy: |
858 | dev_dbg(dev, "PHY DEBUG_R0=0x%08x DEBUG_R1=0x%08x\n", | 831 | dev_dbg(dev, "PHY DEBUG_R0=0x%08x DEBUG_R1=0x%08x\n", |
859 | dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R0), | 832 | dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG0), |
860 | dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R1)); | 833 | dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG1)); |
861 | imx6_pcie_reset_phy(imx6_pcie); | 834 | imx6_pcie_reset_phy(imx6_pcie); |
862 | return ret; | 835 | return ret; |
863 | } | 836 | } |
@@ -993,17 +966,11 @@ static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie) | |||
993 | } | 966 | } |
994 | } | 967 | } |
995 | 968 | ||
996 | static inline bool imx6_pcie_supports_suspend(struct imx6_pcie *imx6_pcie) | ||
997 | { | ||
998 | return (imx6_pcie->drvdata->variant == IMX7D || | ||
999 | imx6_pcie->drvdata->variant == IMX6SX); | ||
1000 | } | ||
1001 | |||
1002 | static int imx6_pcie_suspend_noirq(struct device *dev) | 969 | static int imx6_pcie_suspend_noirq(struct device *dev) |
1003 | { | 970 | { |
1004 | struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); | 971 | struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); |
1005 | 972 | ||
1006 | if (!imx6_pcie_supports_suspend(imx6_pcie)) | 973 | if (!(imx6_pcie->drvdata->flags & IMX6_PCIE_FLAG_SUPPORTS_SUSPEND)) |
1007 | return 0; | 974 | return 0; |
1008 | 975 | ||
1009 | imx6_pcie_pm_turnoff(imx6_pcie); | 976 | imx6_pcie_pm_turnoff(imx6_pcie); |
@@ -1019,7 +986,7 @@ static int imx6_pcie_resume_noirq(struct device *dev) | |||
1019 | struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); | 986 | struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); |
1020 | struct pcie_port *pp = &imx6_pcie->pci->pp; | 987 | struct pcie_port *pp = &imx6_pcie->pci->pp; |
1021 | 988 | ||
1022 | if (!imx6_pcie_supports_suspend(imx6_pcie)) | 989 | if (!(imx6_pcie->drvdata->flags & IMX6_PCIE_FLAG_SUPPORTS_SUSPEND)) |
1023 | return 0; | 990 | return 0; |
1024 | 991 | ||
1025 | imx6_pcie_assert_core_reset(imx6_pcie); | 992 | imx6_pcie_assert_core_reset(imx6_pcie); |
@@ -1249,7 +1216,8 @@ static const struct imx6_pcie_drvdata drvdata[] = { | |||
1249 | [IMX6SX] = { | 1216 | [IMX6SX] = { |
1250 | .variant = IMX6SX, | 1217 | .variant = IMX6SX, |
1251 | .flags = IMX6_PCIE_FLAG_IMX6_PHY | | 1218 | .flags = IMX6_PCIE_FLAG_IMX6_PHY | |
1252 | IMX6_PCIE_FLAG_IMX6_SPEED_CHANGE, | 1219 | IMX6_PCIE_FLAG_IMX6_SPEED_CHANGE | |
1220 | IMX6_PCIE_FLAG_SUPPORTS_SUSPEND, | ||
1253 | }, | 1221 | }, |
1254 | [IMX6QP] = { | 1222 | [IMX6QP] = { |
1255 | .variant = IMX6QP, | 1223 | .variant = IMX6QP, |
@@ -1258,6 +1226,7 @@ static const struct imx6_pcie_drvdata drvdata[] = { | |||
1258 | }, | 1226 | }, |
1259 | [IMX7D] = { | 1227 | [IMX7D] = { |
1260 | .variant = IMX7D, | 1228 | .variant = IMX7D, |
1229 | .flags = IMX6_PCIE_FLAG_SUPPORTS_SUSPEND, | ||
1261 | }, | 1230 | }, |
1262 | [IMX8MQ] = { | 1231 | [IMX8MQ] = { |
1263 | .variant = IMX8MQ, | 1232 | .variant = IMX8MQ, |
diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c index 31f6331ca46f..086e87a40316 100644 --- a/drivers/pci/controller/dwc/pcie-designware.c +++ b/drivers/pci/controller/dwc/pcie-designware.c | |||
@@ -14,12 +14,6 @@ | |||
14 | 14 | ||
15 | #include "pcie-designware.h" | 15 | #include "pcie-designware.h" |
16 | 16 | ||
17 | /* PCIe Port Logic registers */ | ||
18 | #define PLR_OFFSET 0x700 | ||
19 | #define PCIE_PHY_DEBUG_R1 (PLR_OFFSET + 0x2c) | ||
20 | #define PCIE_PHY_DEBUG_R1_LINK_UP (0x1 << 4) | ||
21 | #define PCIE_PHY_DEBUG_R1_LINK_IN_TRAINING (0x1 << 29) | ||
22 | |||
23 | int dw_pcie_read(void __iomem *addr, int size, u32 *val) | 17 | int dw_pcie_read(void __iomem *addr, int size, u32 *val) |
24 | { | 18 | { |
25 | if (!IS_ALIGNED((uintptr_t)addr, size)) { | 19 | if (!IS_ALIGNED((uintptr_t)addr, size)) { |
@@ -334,9 +328,9 @@ int dw_pcie_link_up(struct dw_pcie *pci) | |||
334 | if (pci->ops->link_up) | 328 | if (pci->ops->link_up) |
335 | return pci->ops->link_up(pci); | 329 | return pci->ops->link_up(pci); |
336 | 330 | ||
337 | val = readl(pci->dbi_base + PCIE_PHY_DEBUG_R1); | 331 | val = readl(pci->dbi_base + PCIE_PORT_DEBUG1); |
338 | return ((val & PCIE_PHY_DEBUG_R1_LINK_UP) && | 332 | return ((val & PCIE_PORT_DEBUG1_LINK_UP) && |
339 | (!(val & PCIE_PHY_DEBUG_R1_LINK_IN_TRAINING))); | 333 | (!(val & PCIE_PORT_DEBUG1_LINK_IN_TRAINING))); |
340 | } | 334 | } |
341 | 335 | ||
342 | void dw_pcie_setup(struct dw_pcie *pci) | 336 | void dw_pcie_setup(struct dw_pcie *pci) |
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h index adff0c713665..351636d6d9b5 100644 --- a/drivers/pci/controller/dwc/pcie-designware.h +++ b/drivers/pci/controller/dwc/pcie-designware.h | |||
@@ -41,6 +41,9 @@ | |||
41 | #define PCIE_PORT_DEBUG0 0x728 | 41 | #define PCIE_PORT_DEBUG0 0x728 |
42 | #define PORT_LOGIC_LTSSM_STATE_MASK 0x1f | 42 | #define PORT_LOGIC_LTSSM_STATE_MASK 0x1f |
43 | #define PORT_LOGIC_LTSSM_STATE_L0 0x11 | 43 | #define PORT_LOGIC_LTSSM_STATE_L0 0x11 |
44 | #define PCIE_PORT_DEBUG1 0x72C | ||
45 | #define PCIE_PORT_DEBUG1_LINK_UP BIT(4) | ||
46 | #define PCIE_PORT_DEBUG1_LINK_IN_TRAINING BIT(29) | ||
44 | 47 | ||
45 | #define PCIE_LINK_WIDTH_SPEED_CONTROL 0x80C | 48 | #define PCIE_LINK_WIDTH_SPEED_CONTROL 0x80C |
46 | #define PORT_LOGIC_SPEED_CHANGE BIT(17) | 49 | #define PORT_LOGIC_SPEED_CHANGE BIT(17) |