Skip to content

Commit 9e556dc

Browse files
Huang Shijiebroonie
Huang Shijie
authored andcommitted
spi: spi-imx: only enable the clocks when we start to transfer a message
Current code keeps the clocks enabled all the time, it wastes the power when there is no operaiton on the spi controller. In order to save the power, this patch adds the two hooks: spi_imx_prepare_message: enable the clocks for this message spi_imx_unprepare_message: disable the clocks. This patch also disables the clocks in the end of the probe. Signed-off-by: Huang Shijie <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 31d141e commit 9e556dc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

drivers/spi/spi-imx.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,35 @@ static void spi_imx_cleanup(struct spi_device *spi)
749749
{
750750
}
751751

752+
static int
753+
spi_imx_prepare_message(struct spi_master *master, struct spi_message *msg)
754+
{
755+
struct spi_imx_data *spi_imx = spi_master_get_devdata(master);
756+
int ret;
757+
758+
ret = clk_enable(spi_imx->clk_per);
759+
if (ret)
760+
return ret;
761+
762+
ret = clk_enable(spi_imx->clk_ipg);
763+
if (ret) {
764+
clk_disable(spi_imx->clk_per);
765+
return ret;
766+
}
767+
768+
return 0;
769+
}
770+
771+
static int
772+
spi_imx_unprepare_message(struct spi_master *master, struct spi_message *msg)
773+
{
774+
struct spi_imx_data *spi_imx = spi_master_get_devdata(master);
775+
776+
clk_disable(spi_imx->clk_ipg);
777+
clk_disable(spi_imx->clk_per);
778+
return 0;
779+
}
780+
752781
static int spi_imx_probe(struct platform_device *pdev)
753782
{
754783
struct device_node *np = pdev->dev.of_node;
@@ -810,6 +839,8 @@ static int spi_imx_probe(struct platform_device *pdev)
810839
spi_imx->bitbang.txrx_bufs = spi_imx_transfer;
811840
spi_imx->bitbang.master->setup = spi_imx_setup;
812841
spi_imx->bitbang.master->cleanup = spi_imx_cleanup;
842+
spi_imx->bitbang.master->prepare_message = spi_imx_prepare_message;
843+
spi_imx->bitbang.master->unprepare_message = spi_imx_unprepare_message;
813844
spi_imx->bitbang.master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
814845

815846
init_completion(&spi_imx->xfer_done);
@@ -872,6 +903,8 @@ static int spi_imx_probe(struct platform_device *pdev)
872903

873904
dev_info(&pdev->dev, "probed\n");
874905

906+
clk_disable(spi_imx->clk_ipg);
907+
clk_disable(spi_imx->clk_per);
875908
return ret;
876909

877910
out_clk_put:

0 commit comments

Comments
 (0)