mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 07/12] spi: add bus device
Date: Sun, 14 Oct 2012 23:01:13 +0200	[thread overview]
Message-ID: <1350248478-19359-7-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1350248478-19359-1-git-send-email-plagnioj@jcrosoft.com>

automatically add it as parent if the device does not have a parent already

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/spi/spi.c |   17 ++++++++++++++---
 include/spi/spi.h |    5 +++--
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 44040e5..51892a7 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -75,7 +75,7 @@ struct spi_device *spi_new_device(struct spi_master *master,
 	proxy->mode = chip->mode;
 	proxy->bits_per_word = chip->bits_per_word ? chip->bits_per_word : 8;
 	proxy->dev.platform_data = chip->platform_data;
-	proxy->dev.bus = &spi_bus;
+	proxy->dev.bus = &spi_bus_type;
 	strcpy(proxy->dev.name, chip->name);
 	/* allocate a free id for this chip */
 	proxy->dev.id = DEVICE_ID_DYNAMIC;
@@ -93,6 +93,11 @@ struct spi_device *spi_new_device(struct spi_master *master,
 
 	register_device(&proxy->dev);
 
+	if (!proxy->dev.parent) {
+		proxy->dev.parent = &spi_bus;
+		dev_add_child(proxy->dev.parent, &proxy->dev);
+	}
+
 	return proxy;
 fail:
 	free(proxy);
@@ -285,7 +290,12 @@ static void spi_remove(struct device_d *dev)
 	dev->driver->remove(dev);
 }
 
-struct bus_type spi_bus = {
+struct device_d spi_bus = {
+	.name = "spi",
+	.id = DEVICE_ID_SINGLE,
+};
+
+struct bus_type spi_bus_type = {
 	.name = "spi",
 	.match = spi_match,
 	.probe = spi_probe,
@@ -294,6 +304,7 @@ struct bus_type spi_bus = {
 
 static int spi_bus_init(void)
 {
-	return bus_register(&spi_bus);
+	register_device(&spi_bus);
+	return bus_register(&spi_bus_type);
 }
 pure_initcall(spi_bus_init);
diff --git a/include/spi/spi.h b/include/spi/spi.h
index 1773ca2..fe9c809 100644
--- a/include/spi/spi.h
+++ b/include/spi/spi.h
@@ -430,11 +430,12 @@ static inline ssize_t spi_w8r8(struct spi_device *spi, u8 cmd)
 
 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
-extern struct bus_type spi_bus;
+extern struct device_d spi_bus;
+extern struct bus_type spi_bus_type;
 
 static inline int spi_register_driver(struct driver_d *drv)
 {
-	drv->bus = &spi_bus;
+	drv->bus = &spi_bus_type;
 	return register_driver(drv);
 }
 
-- 
1.7.10.4


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

  parent reply	other threads:[~2012-10-14 21:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-14 20:59 [PATCH 00/12] " Jean-Christophe PLAGNIOL-VILLARD
2012-10-14 21:01 ` [PATCH 01/12] bus_for_each_device/bus_for_each_driver: add () to allow use &bus Jean-Christophe PLAGNIOL-VILLARD
2012-10-14 21:01   ` [PATCH 02/12] platform: add bus device Jean-Christophe PLAGNIOL-VILLARD
2012-10-14 21:01   ` [PATCH 03/12] amba: " Jean-Christophe PLAGNIOL-VILLARD
2012-10-14 21:01   ` [PATCH 04/12] fs: " Jean-Christophe PLAGNIOL-VILLARD
2012-10-14 21:01   ` [PATCH 05/12] mdio: " Jean-Christophe PLAGNIOL-VILLARD
2012-10-14 21:01   ` [PATCH 06/12] i2c: " Jean-Christophe PLAGNIOL-VILLARD
2012-10-14 21:01   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-10-14 21:01   ` [PATCH 08/12] usb: " Jean-Christophe PLAGNIOL-VILLARD
2012-10-14 21:01   ` [PATCH 09/12] fb: " Jean-Christophe PLAGNIOL-VILLARD
2012-10-14 21:01   ` [PATCH 10/12] mtd: register device a pure device Jean-Christophe PLAGNIOL-VILLARD
2012-10-14 21:01   ` [PATCH 11/12] mtd: add parent support Jean-Christophe PLAGNIOL-VILLARD
2012-10-14 21:01   ` [PATCH 12/12] eth: register device a pure device Jean-Christophe PLAGNIOL-VILLARD
2012-10-15  7:10 ` [PATCH 00/12] add bus device Sascha Hauer
2012-10-15 10:23   ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-15 13:21     ` Sascha Hauer
2012-10-15 14:49       ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-15 19:09         ` Sascha Hauer
2012-10-29 10:41         ` 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=1350248478-19359-7-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --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