[U-Boot] [PATCH v1] kirkwood_spi: move all pin multiplexing to spi_claim

Valentin Longchamp valentin.longchamp at keymile.com
Wed Nov 25 10:30:39 CET 2015


The pin multiplexing for the chip select pin was until now done in
spi_setup_slave/spi_free_slave. If an SPI slave was probed, its chip
select pin was never configured back to the possible alternate pin usage
until spi_free_slave was called, even if the bus was released and the
pins give back to the alternate function at the end of the accesses.

This is now regrouped with the pin multiplexing for the MISO/MOSI/SCK
signals in the spi_claim_bus/spi_release_bus. It allows to make sure
that the pin multiplexing in working correctly even if an SPI slave
remains "probed/active".

Signed-off-by: Valentin Longchamp <valentin.longchamp at keymile.com>
---

 drivers/spi/kirkwood_spi.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
index e7b0982..a95ce78 100644
--- a/drivers/spi/kirkwood_spi.c
+++ b/drivers/spi/kirkwood_spi.c
@@ -21,22 +21,11 @@
 static struct kwspi_registers *spireg =
 	(struct kwspi_registers *)MVEBU_SPI_BASE;
 
-#ifdef CONFIG_KIRKWOOD
-static u32 cs_spi_mpp_back[2];
-#endif
-
 struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 				unsigned int max_hz, unsigned int mode)
 {
 	struct spi_slave *slave;
 	u32 data;
-#ifdef CONFIG_KIRKWOOD
-	static const u32 kwspi_mpp_config[2][2] = {
-		{ MPP0_SPI_SCn, 0 }, /* if cs == 0 */
-		{ MPP7_SPI_SCn, 0 } /* if cs != 0 */
-	};
-#endif
-
 	if (!spi_cs_is_valid(bus, cs))
 		return NULL;
 
@@ -58,19 +47,11 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	writel(KWSPI_SMEMRDIRQ, &spireg->irq_cause);
 	writel(KWSPI_IRQMASK, &spireg->irq_mask);
 
-#ifdef CONFIG_KIRKWOOD
-	/* program mpp registers to select  SPI_CSn */
-	kirkwood_mpp_conf(kwspi_mpp_config[cs ? 1 : 0], cs_spi_mpp_back);
-#endif
-
 	return slave;
 }
 
 void spi_free_slave(struct spi_slave *slave)
 {
-#ifdef CONFIG_KIRKWOOD
-	kirkwood_mpp_conf(cs_spi_mpp_back, NULL);
-#endif
 	free(slave);
 }
 
@@ -83,8 +64,20 @@ __attribute__((weak)) int board_spi_claim_bus(struct spi_slave *slave)
 	return 0;
 }
 
+#ifdef CONFIG_KIRKWOOD
+static u32 cs_spi_mpp_back[2];
+#endif
+
 int spi_claim_bus(struct spi_slave *slave)
 {
+#ifdef CONFIG_KIRKWOOD
+	static const u32 kwspi_mpp_config[2][2] = {
+		{ MPP0_SPI_SCn, 0 }, /* if cs == 0 */
+		{ MPP7_SPI_SCn, 0 } /* if cs != 0 */
+	};
+	unsigned int cs = slave->cs;
+#endif
+
 #if defined(CONFIG_SYS_KW_SPI_MPP)
 	u32 config;
 	u32 spi_mpp_config[4];
@@ -113,6 +106,11 @@ int spi_claim_bus(struct spi_slave *slave)
 	kirkwood_mpp_conf(spi_mpp_config, spi_mpp_backup);
 #endif
 
+#ifdef CONFIG_KIRKWOOD
+	/* program mpp registers to select  SPI_CSn */
+	kirkwood_mpp_conf(kwspi_mpp_config[cs ? 1 : 0], cs_spi_mpp_back);
+#endif
+
 	return board_spi_claim_bus(slave);
 }
 
@@ -126,6 +124,9 @@ void spi_release_bus(struct spi_slave *slave)
 	kirkwood_mpp_conf(spi_mpp_backup, NULL);
 #endif
 
+#ifdef CONFIG_KIRKWOOD
+	kirkwood_mpp_conf(cs_spi_mpp_back, NULL);
+#endif
 	board_spi_release_bus(slave);
 }
 
-- 
1.8.3.1



More information about the U-Boot mailing list