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 2/4] add bus registration support
Date: Tue, 16 Aug 2011 07:36:05 +0200	[thread overview]
Message-ID: <1313472967-19324-2-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1313397992-3065-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/base/Makefile |    1 +
 drivers/base/bus.c    |   69 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/driver.h      |   17 ++++++++++++
 3 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100644 drivers/base/bus.c

diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 957ca5a..5f19d4d 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -1,3 +1,4 @@
 obj-y	+= driver.o
+obj-y	+= bus.o
 obj-y	+= platform.o
 obj-y	+= resource.o
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
new file mode 100644
index 0000000..b124ab0
--- /dev/null
+++ b/drivers/base/bus.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include <common.h>
+#include <driver.h>
+
+static int bus_match(struct device_d *dev, struct driver_d *drv)
+{
+	return strcmp(dev->name, drv->name) ? -1 : 0;
+}
+
+static int bus_probe(struct device_d *dev)
+{
+	if (dev->driver->probe)
+		return dev->driver->probe(dev);
+	return 0;
+}
+
+static void bus_remove(struct device_d *dev)
+{
+	if (dev->driver->remove)
+		dev->driver->remove(dev);
+}
+
+struct bus_type bus_bus = {
+	.name = "bus",
+	.match = bus_match,
+	.probe = bus_probe,
+	.remove = bus_remove,
+};
+
+void bus_for_each_device(struct bus_type *bus,
+			 void (*fn)(struct device_d *dev))
+{
+	struct device_d *dev;
+
+	for_each_device(dev) {
+		if (dev->bus == bus)
+			fn(dev);
+	}
+}
+
+int register_bus_driver(struct driver_d *drv)
+{
+	drv->bus = &bus_bus;
+	return register_driver(drv);
+}
+
+int register_bus_device(struct device_d *dev)
+{
+	dev->bus = &bus_bus;
+	return register_device(dev);
+}
diff --git a/include/driver.h b/include/driver.h
index 0b5a652..ab7424e 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -269,6 +269,23 @@ extern struct list_head driver_list;
  */
 #define for_each_device(dev) list_for_each_entry(dev, &device_list, list)
 
+
+int register_bus_driver(struct driver_d *drv);
+int register_bus_device(struct device_d *dev);
+
+/* Iterate over all bus device
+ */
+void bus_for_each_device(struct bus_type *bus,
+			 void (*fn)(struct device_d *dev));
+
+extern struct bus_type bus_bus;
+/* Iterate over all bus
+ */
+static inline void bus_for_each(void (*fn)(struct device_d *dev))
+{
+	bus_for_each_device(&bus_bus, fn);
+}
+
 /* Iterate over all drivers
  */
 #define for_each_driver(drv) list_for_each_entry(drv, &driver_list, list)
-- 
1.7.5.4


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

  parent reply	other threads:[~2011-08-16  5:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-15  8:46 [PATCH] parent fixups Sascha Hauer
2011-08-15  8:46 ` [PATCH 1/7] mci: embed mci_dev into mci_host instead of allocating it seperately Sascha Hauer
2011-08-15  8:46 ` [PATCH 2/7] net: make the ethernet device a child of the hardware device Sascha Hauer
2011-08-15  8:46 ` [PATCH 3/7] net mii: add a parent pointer to miidevs and set it to " Sascha Hauer
2011-08-15  8:46 ` [PATCH 4/7] console: make console device a child of " Sascha Hauer
2011-08-15  8:46 ` [PATCH 5/7] mci: parent fixups Sascha Hauer
2011-08-16 15:39   ` Jean-Christophe PLAGNIOL-VILLARD
2011-08-15  8:46 ` [PATCH 6/7] spi: make the spi devices children of the parent bus Sascha Hauer
2011-08-15  8:46 ` [PATCH 7/7] devinfo: beautify output Sascha Hauer
2011-08-15  9:14 ` [PATCH] parent fixups Jean-Christophe PLAGNIOL-VILLARD
2011-08-15 15:50   ` Sascha Hauer
2011-08-16  5:29     ` Jean-Christophe PLAGNIOL-VILLARD
2011-08-16  5:36 ` [PATCH 1/4] device: update id support to allow device without id Jean-Christophe PLAGNIOL-VILLARD
2011-08-18  5:26   ` Sascha Hauer
2011-08-18  6:27     ` Jean-Christophe PLAGNIOL-VILLARD
2011-08-16  5:36 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2011-08-18  5:14   ` [PATCH 2/4] add bus registration support Sascha Hauer
2011-08-16  5:36 ` [PATCH 3/4] platform_bus: add registrattion to bus Jean-Christophe PLAGNIOL-VILLARD
2011-08-16  5:36 ` [PATCH 4/4] switch all device/driver to platform_device/driver_(un)register Jean-Christophe PLAGNIOL-VILLARD

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=1313472967-19324-2-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