[U-Boot] [PATCH 6/7] spi: Tidy up FDT SPI implementation

Simon Glass sjg at chromium.org
Sun Nov 10 03:37:47 CET 2013


spi_setup_slave_fdt() should get its parameters from the device tree
directly, so tweak this function to do this.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
 drivers/misc/cros_ec_spi.c |  3 +--
 drivers/mtd/spi/sf_probe.c |  2 ++
 drivers/spi/spi.c          | 19 +++++++++++++++++++
 include/spi.h              | 10 ++++------
 4 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/cros_ec_spi.c b/drivers/misc/cros_ec_spi.c
index 202acf2..2fc9110 100644
--- a/drivers/misc/cros_ec_spi.c
+++ b/drivers/misc/cros_ec_spi.c
@@ -135,8 +135,7 @@ int cros_ec_spi_decode_fdt(struct cros_ec_dev *dev, const void *blob)
  */
 int cros_ec_spi_init(struct cros_ec_dev *dev, const void *blob)
 {
-	dev->spi = spi_setup_slave_fdt(blob, dev->parent_node,
-				       dev->cs, dev->max_frequency, 0);
+	dev->spi = spi_setup_slave_fdt(blob, dev->parent_node, dev->node);
 	if (!dev->spi) {
 		debug("%s: Could not setup SPI slave\n", __func__);
 		return -1;
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index ae9a340..c1eb754 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -365,6 +365,7 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 	return spi_flash_probe_slave(spi);
 }
 
+#ifdef CONFIG_OF_SPI_FLASH
 struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
 				      int spi_node)
 {
@@ -373,6 +374,7 @@ struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
 	spi = spi_setup_slave_fdt(blob, slave_node, spi_node);
 	return spi_flash_probe_slave(spi);
 }
+#endif
 
 void spi_flash_free(struct spi_flash *flash)
 {
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ea39d1a..4d02aed 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <fdtdec.h>
 #include <malloc.h>
 #include <spi.h>
 
@@ -24,3 +25,21 @@ void *spi_do_alloc_slave(int offset, int size, unsigned int bus,
 
 	return ptr;
 }
+
+#ifdef CONFIG_OF_SPI
+struct spi_slave *spi_base_setup_slave_fdt(const void *blob, int busnum,
+					   int node)
+{
+	int cs, max_hz, mode = 0;
+
+	cs = fdtdec_get_int(blob, node, "reg", -1);
+	max_hz = fdtdec_get_int(blob, node, "spi-max-frequency", 100000);
+	if (fdtdec_get_bool(blob, node, "spi-cpol"))
+		mode |= SPI_CPOL;
+	if (fdtdec_get_bool(blob, node, "spi-cpha"))
+		mode |= SPI_CPHA;
+	if (fdtdec_get_bool(blob, node, "spi-cs-high"))
+		mode |= SPI_CS_HIGH;
+	return spi_setup_slave(busnum, cs, max_hz, mode);
+}
+#endif
diff --git a/include/spi.h b/include/spi.h
index ad9248b..560cbb3 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -242,13 +242,11 @@ static inline int spi_w8r8(struct spi_slave *slave, unsigned char byte)
  * spi_free_slave() to free it later.
  *
  * @param blob:		Device tree blob
- * @param node:		SPI peripheral node to use
- * @param cs:		Chip select to use
- * @param max_hz:	Maximum SCK rate in Hz (0 for default)
- * @param mode:		Clock polarity, clock phase and other parameters
+ * @param slave_node:	Slave node to use
+ * @param spi_node:	SPI peripheral node to use
  * @return pointer to new spi_slave structure
  */
-struct spi_slave *spi_setup_slave_fdt(const void *blob, int node,
-		unsigned int cs, unsigned int max_hz, unsigned int mode);
+struct spi_slave *spi_setup_slave_fdt(const void *blob, int slave_node,
+				      int spi_node);
 
 #endif	/* _SPI_H_ */
-- 
1.8.4.1



More information about the U-Boot mailing list