Skip to contentSkip to conversation

spi/tegra114: Factor runtime PM out into transfer prepare/unprepare

PATCH In review Mark Brown 2 participants 3 messages Jul 27, 2013 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 spi/tegra114: Factor runtime PM out into transfer prepare/unprepare

From: Mark Brown <[email protected]>

Currently the tegra114 driver acquires a runtime PM reference for the duration of each transfer. This may result in the IP being powered down between transfers which would be at best wasteful. Instead it is better to do this in the callbacks that are generated before and after starting a series of transfers, keeping the IP powered throughout.

---
 drivers/spi/spi-tegra114.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)
drivers/spi/spi-tegra114.c +25 -9
index 8c99c00..e7d48a1 100644
@@ -803,6 +803,20 @@ static int tegra_spi_setup(struct spi_device *spi)
 	return 0;
 }
 
+static int tegra_spi_prepare_transfer(struct spi_master *spi)
+{
+	struct tegra_spi_data *tspi = spi_master_get_devdata(spi);
+	int ret;
+
+	ret = pm_runtime_get_sync(tspi->dev);
+	if (ret < 0) {
+		dev_err(tspi->dev, "runtime PM get failed: %d\n", ret);
+		return ret;
+	}
+
+	return ret;
+}
+
 static int tegra_spi_transfer_one_message(struct spi_master *master,
 			struct spi_message *msg)
 {
@@ -816,14 +830,6 @@ static int tegra_spi_transfer_one_message(struct spi_master *master,
 	msg->status = 0;
 	msg->actual_length = 0;
 
-	ret = pm_runtime_get_sync(tspi->dev);
-	if (ret < 0) {
-		dev_err(tspi->dev, "runtime PM get failed: %d\n", ret);
-		msg->status = ret;
-		spi_finalize_current_message(master);
-		return ret;
-	}
-
 	single_xfer = list_is_singular(&msg->transfers);
 	list_for_each_entry(xfer, &msg->transfers, transfer_list) {
 		INIT_COMPLETION(tspi->xfer_completion);
@@ -859,12 +865,20 @@ static int tegra_spi_transfer_one_message(struct spi_master *master,
 	ret = 0;
 exit:
 	tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1);
-	pm_runtime_put(tspi->dev);
 	msg->status = ret;
 	spi_finalize_current_message(master);
 	return ret;
 }
 
+static int tegra_spi_unprepare_transfer(struct spi_master *spi)
+{
+	struct tegra_spi_data *tspi = spi_master_get_devdata(spi);
+
+	pm_runtime_put(tspi->dev);
+
+	return 0;
+}
+
 static irqreturn_t handle_cpu_based_xfer(struct tegra_spi_data *tspi)
 {
 	struct spi_transfer *t = tspi->curr_xfer;
@@ -1050,7 +1064,9 @@ static int tegra_spi_probe(struct platform_device *pdev)
 	/* the spi->mode bits understood by this driver: */
 	master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
 	master->setup = tegra_spi_setup;
+	master->prepare_transfer_hardware = tegra_spi_prepare_transfer;
 	master->transfer_one_message = tegra_spi_transfer_one_message;
+	master->unprepare_transfer_hardware = tegra_spi_unprepare_transfer;
 	master->num_chipselect = MAX_CHIP_SELECT;
 	master->bus_num = -1;
 
Signature · 1 line
1.8.3.2
#2 lore raw
In reply to a message not in the archive
Quoted 10 lines · Mark Brown

From: Mark Brown <[email protected]>

Currently the tegra114 driver acquires a runtime PM reference for the duration of each transfer. This may result in the IP being powered down between transfers which would be at best wasteful. Instead it is better to do this in the callbacks that are generated before and after starting a series of transfers, keeping the IP powered throughout.

---

The reason I kept this in transfer_one() is because prepare/unprepare was getting called in atomic context. But after the change,

Author: Bryan Freed <[email protected]>
Date:   Wed Mar 13 11:17:40 2013 -0700

spi: Unlock a spinlock before calling into the controller driver.

It is fine to have prepare as blocking call.

author
#4 lore raw
In reply to a message not in the archive
Quoted 3 lines · Laxman Dewangan

The reason I kept this in transfer_one() is because prepare/unprepare was getting called in atomic context. But after the change,

With something like that the best thing to do is to query why there's a restriction and/or fix it - it's a fairly obvious thing to want to do.