Skip to content

Commit 6f8a41b

Browse files
nxpfrankliLorenzo Pieralisi
authored andcommitted
PCI: layerscape: Add suspend/resume for ls1021a
Add suspend/resume support for Layerscape LS1021a. In the suspend path, PME_Turn_Off message is sent to the endpoint to transition the link to L2/L3_Ready state. In this SoC, there is no way to check if the controller has received the PME_To_Ack from the endpoint or not. So to be on the safer side, the driver just waits for PCIE_PME_TO_L2_TIMEOUT_US before asserting the SoC specific PMXMTTURNOFF bit to complete the PME_Turn_Off handshake. Then the link would enter L2/L3 state depending on the VAUX supply. In the resume path, the link is brought back from L2 to L0 by doing a software reset. Link: https://lore.kernel.org/r/20231204160829.2498703-3-Frank.Li@nxp.com Signed-off-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Lorenzo Pieralisi <lpieralisi@kernel.org> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Acked-by: Roy Zang <Roy.Zang@nxp.com>
1 parent 123971a commit 6f8a41b

File tree

1 file changed

+80
-3
lines changed

1 file changed

+80
-3
lines changed

drivers/pci/controller/dwc/pci-layerscape.c

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,28 @@
3535
#define PF_MCR_PTOMR BIT(0)
3636
#define PF_MCR_EXL2S BIT(1)
3737

38+
/* LS1021A PEXn PM Write Control Register */
39+
#define SCFG_PEXPMWRCR(idx) (0x5c + (idx) * 0x64)
40+
#define PMXMTTURNOFF BIT(31)
41+
#define SCFG_PEXSFTRSTCR 0x190
42+
#define PEXSR(idx) BIT(idx)
43+
3844
#define PCIE_IATU_NUM 6
3945

4046
struct ls_pcie_drvdata {
4147
const u32 pf_off;
48+
const struct dw_pcie_host_ops *ops;
4249
int (*exit_from_l2)(struct dw_pcie_rp *pp);
50+
bool scfg_support;
4351
bool pm_support;
4452
};
4553

4654
struct ls_pcie {
4755
struct dw_pcie *pci;
4856
const struct ls_pcie_drvdata *drvdata;
4957
void __iomem *pf_base;
58+
struct regmap *scfg;
59+
int index;
5060
bool big_endian;
5161
};
5262

@@ -171,18 +181,70 @@ static int ls_pcie_host_init(struct dw_pcie_rp *pp)
171181
return 0;
172182
}
173183

184+
static void scfg_pcie_send_turnoff_msg(struct regmap *scfg, u32 reg, u32 mask)
185+
{
186+
/* Send PME_Turn_Off message */
187+
regmap_write_bits(scfg, reg, mask, mask);
188+
189+
/*
190+
* There is no specific register to check for PME_To_Ack from endpoint.
191+
* So on the safe side, wait for PCIE_PME_TO_L2_TIMEOUT_US.
192+
*/
193+
mdelay(PCIE_PME_TO_L2_TIMEOUT_US/1000);
194+
195+
/*
196+
* Layerscape hardware reference manual recommends clearing the PMXMTTURNOFF bit
197+
* to complete the PME_Turn_Off handshake.
198+
*/
199+
regmap_write_bits(scfg, reg, mask, 0);
200+
}
201+
202+
static void ls1021a_pcie_send_turnoff_msg(struct dw_pcie_rp *pp)
203+
{
204+
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
205+
struct ls_pcie *pcie = to_ls_pcie(pci);
206+
207+
scfg_pcie_send_turnoff_msg(pcie->scfg, SCFG_PEXPMWRCR(pcie->index), PMXMTTURNOFF);
208+
}
209+
210+
static int scfg_pcie_exit_from_l2(struct regmap *scfg, u32 reg, u32 mask)
211+
{
212+
/* Reset the PEX wrapper to bring the link out of L2 */
213+
regmap_write_bits(scfg, reg, mask, mask);
214+
regmap_write_bits(scfg, reg, mask, 0);
215+
216+
return 0;
217+
}
218+
219+
static int ls1021a_pcie_exit_from_l2(struct dw_pcie_rp *pp)
220+
{
221+
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
222+
struct ls_pcie *pcie = to_ls_pcie(pci);
223+
224+
return scfg_pcie_exit_from_l2(pcie->scfg, SCFG_PEXSFTRSTCR, PEXSR(pcie->index));
225+
}
226+
174227
static const struct dw_pcie_host_ops ls_pcie_host_ops = {
175228
.host_init = ls_pcie_host_init,
176229
.pme_turn_off = ls_pcie_send_turnoff_msg,
177230
};
178231

232+
static const struct dw_pcie_host_ops ls1021a_pcie_host_ops = {
233+
.host_init = ls_pcie_host_init,
234+
.pme_turn_off = ls1021a_pcie_send_turnoff_msg,
235+
};
236+
179237
static const struct ls_pcie_drvdata ls1021a_drvdata = {
180-
.pm_support = false,
238+
.pm_support = true,
239+
.scfg_support = true,
240+
.ops = &ls1021a_pcie_host_ops,
241+
.exit_from_l2 = ls1021a_pcie_exit_from_l2,
181242
};
182243

183244
static const struct ls_pcie_drvdata layerscape_drvdata = {
184245
.pf_off = 0xc0000,
185246
.pm_support = true,
247+
.ops = &ls_pcie_host_ops,
186248
.exit_from_l2 = ls_pcie_exit_from_l2,
187249
};
188250

@@ -205,6 +267,8 @@ static int ls_pcie_probe(struct platform_device *pdev)
205267
struct dw_pcie *pci;
206268
struct ls_pcie *pcie;
207269
struct resource *dbi_base;
270+
u32 index[2];
271+
int ret;
208272

209273
pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
210274
if (!pcie)
@@ -217,9 +281,8 @@ static int ls_pcie_probe(struct platform_device *pdev)
217281
pcie->drvdata = of_device_get_match_data(dev);
218282

219283
pci->dev = dev;
220-
pci->pp.ops = &ls_pcie_host_ops;
221-
222284
pcie->pci = pci;
285+
pci->pp.ops = pcie->drvdata->ops;
223286

224287
dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
225288
pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
@@ -230,6 +293,20 @@ static int ls_pcie_probe(struct platform_device *pdev)
230293

231294
pcie->pf_base = pci->dbi_base + pcie->drvdata->pf_off;
232295

296+
if (pcie->drvdata->scfg_support) {
297+
pcie->scfg = syscon_regmap_lookup_by_phandle(dev->of_node, "fsl,pcie-scfg");
298+
if (IS_ERR(pcie->scfg)) {
299+
dev_err(dev, "No syscfg phandle specified\n");
300+
return PTR_ERR(pcie->scfg);
301+
}
302+
303+
ret = of_property_read_u32_array(dev->of_node, "fsl,pcie-scfg", index, 2);
304+
if (ret)
305+
return ret;
306+
307+
pcie->index = index[1];
308+
}
309+
233310
if (!ls_pcie_is_bridge(pcie))
234311
return -ENODEV;
235312

0 commit comments

Comments
 (0)