Commit 799f923f authored by Quanyang Wang's avatar Quanyang Wang Committed by Mark Brown

spi: spi-zynqmp-gqspi: fix hang issue when suspend/resume

After calling platform_set_drvdata(pdev, xqspi) in probe, the return
value of dev_get_drvdata(dev) is a pointer to struct zynqmp_qspi but
not struct spi_controller. A wrong structure type passing to the
functions spi_controller_suspend/resume will hang the system.

And we should check the return value of spi_controller_suspend, if
an error is returned, return it to PM subsystem to stop suspend.

Also, GQSPI_EN_MASK should be written to GQSPI_EN_OFST to enable
the spi controller in zynqmp_qspi_resume since it was disabled in
zynqmp_qspi_suspend before.

Fixes: 1c26372e ("spi: spi-zynqmp-gqspi: Update driver to use spi-mem framework")
Signed-off-by: default avatarQuanyang Wang <quanyang.wang@windriver.com>
Link: https://lore.kernel.org/r/20210416004652.2975446-3-quanyang.wang@windriver.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent c6bdae08
...@@ -157,6 +157,7 @@ enum mode_type {GQSPI_MODE_IO, GQSPI_MODE_DMA}; ...@@ -157,6 +157,7 @@ enum mode_type {GQSPI_MODE_IO, GQSPI_MODE_DMA};
* @data_completion: completion structure * @data_completion: completion structure
*/ */
struct zynqmp_qspi { struct zynqmp_qspi {
struct spi_controller *ctlr;
void __iomem *regs; void __iomem *regs;
struct clk *refclk; struct clk *refclk;
struct clk *pclk; struct clk *pclk;
...@@ -827,10 +828,13 @@ static void zynqmp_qspi_read_op(struct zynqmp_qspi *xqspi, u8 rx_nbits, ...@@ -827,10 +828,13 @@ static void zynqmp_qspi_read_op(struct zynqmp_qspi *xqspi, u8 rx_nbits,
*/ */
static int __maybe_unused zynqmp_qspi_suspend(struct device *dev) static int __maybe_unused zynqmp_qspi_suspend(struct device *dev)
{ {
struct spi_controller *ctlr = dev_get_drvdata(dev); struct zynqmp_qspi *xqspi = dev_get_drvdata(dev);
struct zynqmp_qspi *xqspi = spi_controller_get_devdata(ctlr); struct spi_controller *ctlr = xqspi->ctlr;
int ret;
spi_controller_suspend(ctlr); ret = spi_controller_suspend(ctlr);
if (ret)
return ret;
zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, 0x0); zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, 0x0);
...@@ -848,7 +852,10 @@ static int __maybe_unused zynqmp_qspi_suspend(struct device *dev) ...@@ -848,7 +852,10 @@ static int __maybe_unused zynqmp_qspi_suspend(struct device *dev)
*/ */
static int __maybe_unused zynqmp_qspi_resume(struct device *dev) static int __maybe_unused zynqmp_qspi_resume(struct device *dev)
{ {
struct spi_controller *ctlr = dev_get_drvdata(dev); struct zynqmp_qspi *xqspi = dev_get_drvdata(dev);
struct spi_controller *ctlr = xqspi->ctlr;
zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, GQSPI_EN_MASK);
spi_controller_resume(ctlr); spi_controller_resume(ctlr);
...@@ -865,7 +872,7 @@ static int __maybe_unused zynqmp_qspi_resume(struct device *dev) ...@@ -865,7 +872,7 @@ static int __maybe_unused zynqmp_qspi_resume(struct device *dev)
*/ */
static int __maybe_unused zynqmp_runtime_suspend(struct device *dev) static int __maybe_unused zynqmp_runtime_suspend(struct device *dev)
{ {
struct zynqmp_qspi *xqspi = (struct zynqmp_qspi *)dev_get_drvdata(dev); struct zynqmp_qspi *xqspi = dev_get_drvdata(dev);
clk_disable_unprepare(xqspi->refclk); clk_disable_unprepare(xqspi->refclk);
clk_disable_unprepare(xqspi->pclk); clk_disable_unprepare(xqspi->pclk);
...@@ -883,7 +890,7 @@ static int __maybe_unused zynqmp_runtime_suspend(struct device *dev) ...@@ -883,7 +890,7 @@ static int __maybe_unused zynqmp_runtime_suspend(struct device *dev)
*/ */
static int __maybe_unused zynqmp_runtime_resume(struct device *dev) static int __maybe_unused zynqmp_runtime_resume(struct device *dev)
{ {
struct zynqmp_qspi *xqspi = (struct zynqmp_qspi *)dev_get_drvdata(dev); struct zynqmp_qspi *xqspi = dev_get_drvdata(dev);
int ret; int ret;
ret = clk_prepare_enable(xqspi->pclk); ret = clk_prepare_enable(xqspi->pclk);
...@@ -1090,6 +1097,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) ...@@ -1090,6 +1097,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
xqspi = spi_controller_get_devdata(ctlr); xqspi = spi_controller_get_devdata(ctlr);
xqspi->dev = dev; xqspi->dev = dev;
xqspi->ctlr = ctlr;
platform_set_drvdata(pdev, xqspi); platform_set_drvdata(pdev, xqspi);
xqspi->regs = devm_platform_ioremap_resource(pdev, 0); xqspi->regs = devm_platform_ioremap_resource(pdev, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment