[PATCH 2/5] spi: improve devicetree support

Sascha Hauer s.hauer at pengutronix.de
Tue May 21 03:38:12 EDT 2013


- zero spi_board_info structure to not accidently pass
  unitilialized fields
- parse spi-max-frequency property from devicetree
- parse mode flags from devicetree

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/spi/spi.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index d58b664..f460a7a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -108,9 +108,20 @@ void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
 	struct property *reg;
 
 	device_node_for_nach_child(node, n) {
-		chip.name = n->name;
+		memset(&chip, 0, sizeof(chip));
+		chip.name = xstrdup(n->name);
 		chip.bus_num = master->bus_num;
-		chip.max_speed_hz = 300000; /* FIXME */
+		/* Mode (clock phase/polarity/etc.) */
+		if (of_find_property(n, "spi-cpha"))
+			chip.mode |= SPI_CPHA;
+		if (of_find_property(n, "spi-cpol"))
+			chip.mode |= SPI_CPOL;
+		if (of_find_property(n, "spi-cs-high"))
+			chip.mode |= SPI_CS_HIGH;
+		if (of_find_property(n, "spi-3wire"))
+			chip.mode |= SPI_3WIRE;
+		of_property_read_u32(n, "spi-max-frequency",
+				&chip.max_speed_hz);
 		reg = of_find_property(n, "reg");
 		if (!reg)
 			continue;
-- 
1.8.2.rc2




More information about the barebox mailing list