Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: orion: enable clocks before spi_setup

The spi-orion driver disables its clocks whenever it is not used.
In usual case during boot (i.e. using SPI flash) it is not a problem,
as the child device driver is present and probed along with
spi_register_master() execution.

However in case the child device driver is not ready
(e.g. when its type is module_spi_driver) the spi_setup() callback
can be called after the spi-orion probe. It may happen,
that as a result there will be an attempt to access controller's
registers with the clocks disabled.

Prevent such situations and make sure the clocks are on,
each time the spi_setup() is called.

Signed-off-by: Marcin Wojtas <mw@semihalf.com>
Signed-off-by: Konstantin Porotchkin <kostap@marvell.com>
Link: https://lore.kernel.org/r/20201223103827.29721-2-kostap@marvell.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Marcin Wojtas and committed by
Mark Brown
e2be7031 a34d4197

+22 -1
+22 -1
drivers/spi/spi-orion.c
··· 96 96 struct clk *clk; 97 97 struct clk *axi_clk; 98 98 const struct orion_spi_dev *devdata; 99 + struct device *dev; 99 100 100 101 struct orion_child_options child[ORION_NUM_CHIPSELECTS]; 101 102 }; 103 + 104 + #ifdef CONFIG_PM 105 + static int orion_spi_runtime_suspend(struct device *dev); 106 + static int orion_spi_runtime_resume(struct device *dev); 107 + #endif 102 108 103 109 static inline void __iomem *spi_reg(struct orion_spi *orion_spi, u32 reg) 104 110 { ··· 513 507 514 508 static int orion_spi_setup(struct spi_device *spi) 515 509 { 516 - return orion_spi_setup_transfer(spi, NULL); 510 + int ret; 511 + #ifdef CONFIG_PM 512 + struct orion_spi *orion_spi = spi_master_get_devdata(spi->master); 513 + struct device *dev = orion_spi->dev; 514 + 515 + orion_spi_runtime_resume(dev); 516 + #endif 517 + 518 + ret = orion_spi_setup_transfer(spi, NULL); 519 + 520 + #ifdef CONFIG_PM 521 + orion_spi_runtime_suspend(dev); 522 + #endif 523 + 524 + return ret; 517 525 } 518 526 519 527 static int orion_spi_reset(struct orion_spi *orion_spi) ··· 650 630 651 631 spi = spi_master_get_devdata(master); 652 632 spi->master = master; 633 + spi->dev = &pdev->dev; 653 634 654 635 of_id = of_match_device(orion_spi_of_match_table, &pdev->dev); 655 636 devdata = (of_id) ? of_id->data : &orion_spi_dev_data;