mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 05/15] spi: add oftree support
Date: Wed, 12 Sep 2012 22:06:37 +0200	[thread overview]
Message-ID: <1347480407-16865-6-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1347480407-16865-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/spi/spi.c |   34 +++++++++++++++++++++++++++++++++-
 include/spi/spi.h |    6 ++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 4416783..bbb7679 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -83,6 +83,7 @@ struct spi_device *spi_new_device(struct spi_master *master,
 	/* allocate a free id for this chip */
 	proxy->dev.id = DEVICE_ID_DYNAMIC;
 	proxy->dev.type_data = proxy;
+	proxy->dev.device_node = chip->device_node;
 	dev_add_child(master->dev, &proxy->dev);
 
 	/* drivers may modify this initial i/o setup */
@@ -102,6 +103,29 @@ fail:
 }
 EXPORT_SYMBOL(spi_new_device);
 
+#ifdef CONFIG_OFTREE
+#include <of.h>
+
+void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
+{
+	struct device_node *n;
+	struct spi_board_info chip;
+	struct property *reg;
+
+	device_node_for_nach_child(node, n) {
+		chip.name = n->name;
+		chip.bus_num = master->bus_num;
+		chip.max_speed_hz = 300000; /* FIXME */
+		reg = of_find_property(n, "reg");
+		if (!reg)
+			continue;
+		chip.chip_select = of_read_number(reg->value, 1);
+		chip.device_node = n;
+		spi_register_board_info(&chip, 1);
+	}
+}
+#endif
+
 /**
  * spi_register_board_info - register SPI devices for a given board
  * @info: array of chip descriptors
@@ -145,7 +169,7 @@ static void scan_boardinfo(struct spi_master *master)
 		unsigned		n;
 
 		for (n = bi->n_board_info; n > 0; n--, chip++) {
-			debug("%s %d %d\n", __FUNCTION__, chip->bus_num, master->bus_num);
+			printf("%s %d %d\n", __FUNCTION__, chip->bus_num, master->bus_num);
 			if (chip->bus_num != master->bus_num)
 				continue;
 			/* NOTE: this relies on spi_new_device to
@@ -156,6 +180,8 @@ static void scan_boardinfo(struct spi_master *master)
 	}
 }
 
+static LIST_HEAD(spi_master_list);
+
 /**
  * spi_register_master - register SPI master controller
  * @master: initialized master, originally from spi_alloc_master()
@@ -188,6 +214,8 @@ int spi_register_master(struct spi_master *master)
 	if (master->num_chipselect == 0)
 		return -EINVAL;
 
+	list_add_tail(&master->list, &spi_master_list);
+
 	/* populate children from any spi device tables */
 	scan_boardinfo(master);
 	status = 0;
@@ -245,6 +273,10 @@ EXPORT_SYMBOL(spi_write_then_read);
 
 static int spi_match(struct device_d *dev, struct driver_d *drv)
 {
+	if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node &&
+			drv->of_compatible)
+		return of_match(dev, drv);
+
 	return strcmp(dev->name, drv->name) ? -1 : 0;
 }
 
diff --git a/include/spi/spi.h b/include/spi/spi.h
index 569cdcd..1773ca2 100644
--- a/include/spi/spi.h
+++ b/include/spi/spi.h
@@ -17,6 +17,7 @@ struct spi_board_info {
 	u8	mode;
 	u8	bits_per_word;
 	void	*platform_data;
+	struct device_node *device_node;
 };
 
 /**
@@ -163,6 +164,8 @@ struct spi_master {
 
 	/* called on release() to free memory provided by spi_master */
 	void			(*cleanup)(struct spi_device *spi);
+
+	struct list_head list;
 };
 
 /*---------------------------------------------------------------------------*/
@@ -434,4 +437,7 @@ static inline int spi_register_driver(struct driver_d *drv)
 	drv->bus = &spi_bus;
 	return register_driver(drv);
 }
+
+void spi_of_register_slaves(struct spi_master *master, struct device_node *node);
+
 #endif /* __INCLUDE_SPI_H */
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2012-09-12 20:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-12 20:06 [PATCH] devicetree probe support Sascha Hauer
2012-09-12 20:06 ` [PATCH 01/15] driver: add dev_get_drvdata function Sascha Hauer
2012-09-12 20:06 ` [PATCH 02/15] of: add devicetree probing support Sascha Hauer
2012-09-18 15:48   ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-12 20:06 ` [PATCH 03/15] oftree command: Add devicetree probe support Sascha Hauer
2012-09-12 20:06 ` [PATCH 04/15] of: Add devicetree partition parsing Sascha Hauer
2012-09-12 20:06 ` Sascha Hauer [this message]
2012-09-12 20:06 ` [PATCH 06/15] ARM i.MX: Use platform_device_id for gpio driver Sascha Hauer
2012-09-12 20:06 ` [PATCH 07/15] ARM i.MX: implement clocksource as driver Sascha Hauer
2012-09-17 16:17   ` Sascha Hauer
2012-09-12 20:06 ` [PATCH 08/15] serial i.MX: oftree support Sascha Hauer
2012-09-12 20:06 ` [PATCH 09/15] net fec_imx: " Sascha Hauer
2012-09-12 20:06 ` [PATCH 10/15] spi imx: dt support Sascha Hauer
2012-09-12 20:06 ` [PATCH 11/15] mfd mc13xxx: Add devicetree support Sascha Hauer
2012-09-12 20:06 ` [PATCH 12/15] cfi-flash: Add devicetree probe support Sascha Hauer
2012-09-12 20:06 ` [PATCH 13/15] mci i.MX esdhc: Add oftree support Sascha Hauer
2012-09-12 20:06 ` [PATCH 14/15] ARM i.MX: add devicetree support for gpio driver Sascha Hauer
2012-09-12 20:06 ` [PATCH 15/15] ARM i.MX: Add devicetree support for clocksource driver Sascha Hauer
2012-09-20 18:45 ` [PATCH] devicetree probe support Jean-Christophe PLAGNIOL-VILLARD
2012-09-20 18:51   ` [PATCH 1/1] fb: add it's own bus for fb devices Jean-Christophe PLAGNIOL-VILLARD
2012-09-20 21:17     ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1347480407-16865-6-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox