Skip to content

Commit be721b4

Browse files
computersforpeacebroonie
authored andcommitted
spi: rockchip: Resolve unbalanced runtime PM / system PM handling
Commit e882575 ("spi: rockchip: Suspend and resume the bus during NOIRQ_SYSTEM_SLEEP_PM ops") stopped respecting runtime PM status and simply disabled clocks unconditionally when suspending the system. This causes problems when the device is already runtime suspended when we go to sleep -- in which case we double-disable clocks and produce a WARNing. Switch back to pm_runtime_force_{suspend,resume}(), because that still seems like the right thing to do, and the aforementioned commit makes no explanation why it stopped using it. Also, refactor some of the resume() error handling, because it's not actually a good idea to re-disable clocks on failure. Fixes: e882575 ("spi: rockchip: Suspend and resume the bus during NOIRQ_SYSTEM_SLEEP_PM ops") Cc: [email protected] Reported-by: Ondřej Jirman <[email protected]> Closes: https://lore.kernel.org/lkml/20220621154218.sau54jeij4bunf56@core/ Signed-off-by: Brian Norris <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 5be63fc commit be721b4

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

drivers/spi/spi-rockchip.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -945,14 +945,16 @@ static int rockchip_spi_suspend(struct device *dev)
945945
{
946946
int ret;
947947
struct spi_controller *ctlr = dev_get_drvdata(dev);
948-
struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
949948

950949
ret = spi_controller_suspend(ctlr);
951950
if (ret < 0)
952951
return ret;
953952

954-
clk_disable_unprepare(rs->spiclk);
955-
clk_disable_unprepare(rs->apb_pclk);
953+
ret = pm_runtime_force_suspend(dev);
954+
if (ret < 0) {
955+
spi_controller_resume(ctlr);
956+
return ret;
957+
}
956958

957959
pinctrl_pm_select_sleep_state(dev);
958960

@@ -963,25 +965,14 @@ static int rockchip_spi_resume(struct device *dev)
963965
{
964966
int ret;
965967
struct spi_controller *ctlr = dev_get_drvdata(dev);
966-
struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
967968

968969
pinctrl_pm_select_default_state(dev);
969970

970-
ret = clk_prepare_enable(rs->apb_pclk);
971+
ret = pm_runtime_force_resume(dev);
971972
if (ret < 0)
972973
return ret;
973974

974-
ret = clk_prepare_enable(rs->spiclk);
975-
if (ret < 0)
976-
clk_disable_unprepare(rs->apb_pclk);
977-
978-
ret = spi_controller_resume(ctlr);
979-
if (ret < 0) {
980-
clk_disable_unprepare(rs->spiclk);
981-
clk_disable_unprepare(rs->apb_pclk);
982-
}
983-
984-
return 0;
975+
return spi_controller_resume(ctlr);
985976
}
986977
#endif /* CONFIG_PM_SLEEP */
987978

0 commit comments

Comments
 (0)