mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/12] add bus device
@ 2012-10-14 20:59 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-15  7:10 ` [PATCH 00/12] add bus device Sascha Hauer
  0 siblings, 2 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 20:59 UTC (permalink / raw)
  To: barebox

Hi,

we have now a nice output per bus

barebox@ST SPEARr1340 EVB:/
# devinfo 
devices:
`---- platfrom
     `---- mem0
          `---- 0x00000000-0x3fffffff: /dev/ram0
     `---- smp_twd
     `---- mem1
          `---- 0x00000000-0x0000251f: /dev/defaultenv
     `---- mem2
          `---- 0x00000000-0xfffffffe: /dev/mem
     `---- designware_eth0
          `---- miibus0
          `---- eth0
     `---- fsmc-nand
          `---- nand0
               `---- 0x00000000-0x7fffffff: /dev/nand0
               `---- 0x00000000-0x0000ffff: /dev/xloader
               `---- 0x00010000-0x0004ffff: /dev/self_raw
               `---- 0x00050000-0x0006ffff: /dev/env_raw
               `---- 0x00000000-0x0003ffff: /dev/nand0.xloader
               `---- 0x00040000-0x0007ffff: /dev/nand0.meminit
               `---- 0x00080000-0x0027ffff: /dev/nand0.barebox
               `---- 0x00280000-0x0057ffff: /dev/nand0.kernel
               `---- 0x00580000-0x01b7ffff: /dev/nand0.rootfs
               `---- 0x01b80000-0x07f7ffff: /dev/nand0.userfs
               `---- 0x07f80000-0x07fdffff: /dev/nand0.free
               `---- 0x07fe0000-0x07ffffff: /dev/nand0.bareboxenv
     `---- smi
          `---- smi0
               `---- 0x00000000-0x007fffff: /dev/smi0
     `---- sdhci-spear
          `---- mci0
               `---- 0x00000000-0x1e3dffff: /dev/disk0
               `---- 0x0001da00-0x1e3d1fff: /dev/disk0.0
`---- amba
     `---- uart-pl0110
          `---- cs0
     `---- pl061_gpio0
     `---- pl061_gpio1
     `---- ssp-pl0220
          `---- m25p0
               `---- 0x00000000-0x0000ffff: /dev/m25p0
`---- mdio_bus
`---- usb
`---- spi
`---- i2c
`---- fb
`---- fs
     `---- ramfs0
     `---- devfs0
`---- net
`---- global

drivers:
uart-pl011
   smp_twd
pl061_gpio
     ramfs
     devfs
       fat
Generic PHY
designware_eth
 fsmc-nand
       smi
      m25p
 ssp-pl022
       mci
sdhci-spear
        fb
       mem

The following changes since commit 461e7d7aefb128a63b84687ba7e361473ada91c6:

  mtd-core: add writesize in MEMGETINFO ioctl (2012-10-13 14:30:50 +0200)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git tags/bus_device

for you to fetch changes up to 056b5fb309edfb8f16375f84869d3e7993cb9854:

  eth: register device a pure device (2012-10-14 14:04:07 +0800)

----------------------------------------------------------------
add bus device

This patch serie add a pure device for each bus

And set this device to each bus device as a parent if the device
does not have a parent already

This add swith eth_device and mtd to pure device as they have no driver and
does not need to be probed

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (12):
      bus_for_each_device/bus_for_each_driver: add () to allow use &bus
      platform: add bus device
      amba: add bus device
      fs: add bus device
      mdio: add bus device
      i2c: add bus device
      spi: add bus device
      usb: add bus device
      fb: add bus device
      mtd: register device a pure device
      mtd: add parent support
      eth: register device a pure device

 drivers/amba/bus.c                |    8 ++++++++
 drivers/base/platform.c           |   18 ++++++++++++++----
 drivers/i2c/i2c.c                 |   26 +++++++++++++++++++-------
 drivers/mtd/core.c                |    6 +++++-
 drivers/mtd/devices/docg3.c       |    1 +
 drivers/mtd/nand/atmel_nand.c     |    1 +
 drivers/mtd/nand/nand_imx.c       |    2 +-
 drivers/mtd/nand/nand_mxs.c       |    1 +
 drivers/mtd/nand/nand_omap_gpmc.c |    1 +
 drivers/mtd/nand/nand_s3c24xx.c   |    1 +
 drivers/mtd/nand/nomadik_nand.c   |    1 +
 drivers/net/phy/mdio_bus.c        |    6 ++++++
 drivers/spi/spi.c                 |   17 ++++++++++++++---
 drivers/usb/core/usb.c            |   11 +++++++++++
 drivers/video/fb.c                |   17 +++++++++++++----
 fs/fs.c                           |   23 +++++++++++++++--------
 include/driver.h                  |    7 ++++---
 include/fb.h                      |    3 ++-
 include/i2c/i2c.h                 |    5 +++--
 include/linux/mtd/mtd.h           |    2 +-
 include/spi/spi.h                 |    5 +++--
 include/usb/usb.h                 |    1 +
 net/eth.c                         |    2 +-
 23 files changed, 127 insertions(+), 38 deletions(-)

Best Regards,
J.

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 01/12] bus_for_each_device/bus_for_each_driver: add () to allow use &bus
  2012-10-14 20:59 [PATCH 00/12] add bus device Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-14 21:01 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-14 21:01   ` [PATCH 02/12] platform: add bus device Jean-Christophe PLAGNIOL-VILLARD
                     ` (10 more replies)
  2012-10-15  7:10 ` [PATCH 00/12] add bus device Sascha Hauer
  1 sibling, 11 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 21:01 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/driver.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/driver.h b/include/driver.h
index 4918054..dd22c77 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -393,11 +393,11 @@ extern struct list_head bus_list;
 
 /* Iterate over all devices of a bus
  */
-#define bus_for_each_device(bus, dev) list_for_each_entry(dev, &bus->device_list, bus_list)
+#define bus_for_each_device(bus, dev) list_for_each_entry(dev, &(bus)->device_list, bus_list)
 
 /* Iterate over all drivers of a bus
  */
-#define bus_for_each_driver(bus, drv) list_for_each_entry(drv, &bus->driver_list, bus_list)
+#define bus_for_each_driver(bus, drv) list_for_each_entry(drv, &(bus)->driver_list, bus_list)
 
 extern struct bus_type platform_bus;
 
-- 
1.7.10.4


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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 02/12] platform: add bus device
  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   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-14 21:01   ` [PATCH 03/12] amba: " Jean-Christophe PLAGNIOL-VILLARD
                     ` (9 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 21:01 UTC (permalink / raw)
  To: barebox

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/base/platform.c |   18 ++++++++++++++----
 include/driver.h        |    3 ++-
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index ea4e37b..08787f6 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -57,19 +57,28 @@ static void platform_remove(struct device_d *dev)
 
 int platform_driver_register(struct driver_d *drv)
 {
-	drv->bus = &platform_bus;
+	drv->bus = &platform_bus_type;
 
 	return register_driver(drv);
 }
 
 int platform_device_register(struct device_d *new_device)
 {
-	new_device->bus = &platform_bus;
+	new_device->bus = &platform_bus_type;
+	if (!new_device->parent) {
+		new_device->parent = &platform_bus;
+		dev_add_child(new_device->parent, new_device);
+	}
 
 	return register_device(new_device);
 }
 
-struct bus_type platform_bus = {
+struct device_d platform_bus = {
+	.name = "platfrom",
+	.id = DEVICE_ID_SINGLE,
+};
+
+struct bus_type platform_bus_type = {
 	.name = "platform",
 	.match = platform_match,
 	.probe = platform_probe,
@@ -78,6 +87,7 @@ struct bus_type platform_bus = {
 
 static int plarform_init(void)
 {
-	return bus_register(&platform_bus);
+	register_device(&platform_bus);
+	return bus_register(&platform_bus_type);
 }
 pure_initcall(plarform_init);
diff --git a/include/driver.h b/include/driver.h
index dd22c77..5d85c1d 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -399,7 +399,8 @@ extern struct list_head bus_list;
  */
 #define bus_for_each_driver(bus, drv) list_for_each_entry(drv, &(bus)->driver_list, bus_list)
 
-extern struct bus_type platform_bus;
+extern struct bus_type platform_bus_type;
+extern struct device_d platform_bus;
 
 int platform_driver_register(struct driver_d *drv);
 int platform_device_register(struct device_d *new_device);
-- 
1.7.10.4


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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 03/12] amba: add bus device
  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   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-14 21:01   ` [PATCH 04/12] fs: " Jean-Christophe PLAGNIOL-VILLARD
                     ` (8 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 21:01 UTC (permalink / raw)
  To: barebox

automatically add amba_device as parent of any amba device

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/amba/bus.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index f0a40b6..581a25c 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -72,6 +72,11 @@ static void amba_remove(struct device_d *dev)
 	drv->remove(pcdev);
 }
 
+struct device_d amba_bus = {
+	.name = "amba",
+	.id = DEVICE_ID_SINGLE,
+};
+
 struct bus_type amba_bustype = {
 	.name = "amba",
 	.match = amba_match,
@@ -153,6 +158,8 @@ int amba_device_add(struct amba_device *dev)
 		goto err_release;
 
  skip_probe:
+	dev->dev.parent = &amba_bus;
+	dev_add_child(dev->dev.parent, &dev->dev);
 	ret = register_device(&dev->dev);
 	if (ret)
 		goto err_release;
@@ -212,6 +219,7 @@ struct amba_device *amba_device_alloc(const char *name, int id, resource_size_t
 
 static int amba_bus_init(void)
 {
+	register_device(&amba_bus);
 	return bus_register(&amba_bustype);
 }
 pure_initcall(amba_bus_init);
-- 
1.7.10.4


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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 04/12] fs: add bus device
  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   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-14 21:01   ` [PATCH 05/12] mdio: " Jean-Christophe PLAGNIOL-VILLARD
                     ` (7 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 21:01 UTC (permalink / raw)
  To: barebox

automatically add it as parent of any fs device

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 fs/fs.c |   23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index b9a1f17..b63a005 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1131,7 +1131,12 @@ static void fs_remove(struct device_d *dev)
 	free(fsdev);
 }
 
-struct bus_type fs_bus = {
+struct device_d fs_bus = {
+	.name = "fs",
+	.id = DEVICE_ID_SINGLE,
+};
+
+struct bus_type fs_bus_type = {
 	.name = "fs",
 	.match = fs_match,
 	.probe = fs_probe,
@@ -1140,13 +1145,14 @@ struct bus_type fs_bus = {
 
 static int fs_bus_init(void)
 {
-	return bus_register(&fs_bus);
+	register_device(&fs_bus);
+	return bus_register(&fs_bus_type);
 }
 pure_initcall(fs_bus_init);
 
 int register_fs_driver(struct fs_driver_d *fsdrv)
 {
-	fsdrv->drv.bus = &fs_bus;
+	fsdrv->drv.bus = &fs_bus_type;
 	register_driver(&fsdrv->drv);
 
 	return 0;
@@ -1162,10 +1168,7 @@ static const char *detect_fs(const char *filename)
 	if (type == filetype_unknown)
 		return NULL;
 
-	for_each_driver(drv) {
-		if (drv->bus != &fs_bus)
-			continue;
-
+	bus_for_each_driver(&fs_bus_type, drv) {
 		fdrv = drv_to_fs_driver(drv);
 
 		if (type == fdrv->type)
@@ -1217,11 +1220,15 @@ int mount(const char *device, const char *fsname, const char *_path)
 	safe_strncpy(fsdev->dev.name, fsname, MAX_DRIVER_NAME);
 	fsdev->dev.id = get_free_deviceid(fsdev->dev.name);
 	fsdev->path = xstrdup(path);
-	fsdev->dev.bus = &fs_bus;
+	fsdev->dev.bus = &fs_bus_type;
 
 	if (!strncmp(device, "/dev/", 5))
 		fsdev->cdev = cdev_by_name(device + 5);
 
+	if (!fsdev->dev.parent) {
+		fsdev->dev.parent = &fs_bus;
+		dev_add_child(fsdev->dev.parent, &fsdev->dev);
+	}
 	ret = register_device(&fsdev->dev);
 	if (ret)
 		goto err_register;
-- 
1.7.10.4


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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 05/12] mdio: add bus device
  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
                     ` (2 preceding siblings ...)
  2012-10-14 21:01   ` [PATCH 04/12] fs: " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-14 21:01   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-14 21:01   ` [PATCH 06/12] i2c: " Jean-Christophe PLAGNIOL-VILLARD
                     ` (6 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 21:01 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/net/phy/mdio_bus.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index b49f714..eba3e1f 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -233,6 +233,11 @@ static void mdio_bus_remove(struct device_d *_dev)
 	devfs_remove(&dev->cdev);
 }
 
+struct device_d mdio_bus = {
+	.name = "mdio_bus",
+	.id = DEVICE_ID_SINGLE,
+};
+
 struct bus_type mdio_bus_type = {
 	.name		= "mdio_bus",
 	.match		= mdio_bus_match,
@@ -243,6 +248,7 @@ EXPORT_SYMBOL(mdio_bus_type);
 
 static int mdio_bus_init(void)
 {
+	register_device(&mdio_bus);
 	return bus_register(&mdio_bus_type);
 }
 pure_initcall(mdio_bus_init);
-- 
1.7.10.4


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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 06/12] i2c: add bus device
  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
                     ` (3 preceding siblings ...)
  2012-10-14 21:01   ` [PATCH 05/12] mdio: " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-14 21:01   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-14 21:01   ` [PATCH 07/12] spi: " Jean-Christophe PLAGNIOL-VILLARD
                     ` (5 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 21:01 UTC (permalink / raw)
  To: barebox

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/i2c/i2c.c |   26 +++++++++++++++++++-------
 include/i2c/i2c.h |    5 +++--
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 27fd256..dd7dfd7 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -252,12 +252,20 @@ struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
 	strcpy(client->dev.name, chip->type);
 	client->dev.type_data = client;
 	client->dev.platform_data = chip->platform_data;
-	client->dev.bus = &i2c_bus;
+	client->dev.bus = &i2c_bus_type;
 	client->adapter = adapter;
 	client->addr = chip->addr;
 
 	status = register_device(&client->dev);
 
+	if (status)
+		goto fail;
+
+	if (!client->dev.parent) {
+		client->dev.parent = &i2c_bus;
+		dev_add_child(client->dev.parent, &client->dev);
+	}
+
 #if 0
 	/* drivers may modify this initial i/o setup */
 	status = master->setup(client);
@@ -270,11 +278,9 @@ struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
 
 	return client;
 
-#if 0
- fail:
-	free(proxy);
+fail:
+	free(client);
 	return NULL;
-#endif
 }
 EXPORT_SYMBOL(i2c_new_device);
 
@@ -390,7 +396,12 @@ static void i2c_remove(struct device_d *dev)
 	dev->driver->remove(dev);
 }
 
-struct bus_type i2c_bus = {
+struct device_d i2c_bus = {
+	.name = "i2c",
+	.id = DEVICE_ID_SINGLE,
+};
+
+struct bus_type i2c_bus_type = {
 	.name = "i2c",
 	.match = i2c_match,
 	.probe = i2c_probe,
@@ -399,6 +410,7 @@ struct bus_type i2c_bus = {
 
 static int i2c_bus_init(void)
 {
-	return bus_register(&i2c_bus);
+	register_device(&i2c_bus);
+	return bus_register(&i2c_bus_type);
 }
 pure_initcall(i2c_bus_init);
diff --git a/include/i2c/i2c.h b/include/i2c/i2c.h
index de2a7ea..20d7f65 100644
--- a/include/i2c/i2c.h
+++ b/include/i2c/i2c.h
@@ -139,11 +139,12 @@ extern int i2c_write_reg(struct i2c_client *client, u32 addr, const u8 *buf, u16
 
 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
-extern struct bus_type i2c_bus;
+extern struct device_d i2c_bus;
+extern struct bus_type i2c_bus_type;
 
 static inline int i2c_register_driver(struct driver_d *drv)
 {
-	drv->bus = &i2c_bus;
+	drv->bus = &i2c_bus_type;
 	return register_driver(drv);
 }
 
-- 
1.7.10.4


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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 07/12] spi: add bus device
  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
                     ` (4 preceding siblings ...)
  2012-10-14 21:01   ` [PATCH 06/12] i2c: " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-14 21:01   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-14 21:01   ` [PATCH 08/12] usb: " Jean-Christophe PLAGNIOL-VILLARD
                     ` (4 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 21:01 UTC (permalink / raw)
  To: barebox

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 08/12] usb: add bus device
  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
                     ` (5 preceding siblings ...)
  2012-10-14 21:01   ` [PATCH 07/12] spi: " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-14 21:01   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-14 21:01   ` [PATCH 09/12] fb: " Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 21:01 UTC (permalink / raw)
  To: barebox

automatically add usb_device to it if they do not have a parent already

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/usb/core/usb.c |   11 +++++++++++
 include/usb/usb.h      |    1 +
 2 files changed, 12 insertions(+)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 9dc931b..0d610d6 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -437,6 +437,11 @@ static int usb_new_device(struct usb_device *dev)
 
 	print_usb_device(dev);
 
+	if (!dev->dev.parent) {
+		dev->dev.parent = &usb_bus;
+		dev_add_child(dev->dev.parent, &dev->dev);
+	}
+
 	register_device(&dev->dev);
 	list_add_tail(&dev->list, &usb_device_list);
 
@@ -1411,6 +1416,11 @@ static void usb_remove(struct device_d *dev)
 	usbdrv->disconnect(usbdev);
 }
 
+struct device_d usb_bus = {
+	.name = "usb",
+	.id = DEVICE_ID_SINGLE,
+};
+
 struct bus_type usb_bus_type = {
 	.name	= "usb",
 	.match	= usb_match,
@@ -1420,6 +1430,7 @@ struct bus_type usb_bus_type = {
 
 static int usb_bus_init(void)
 {
+	register_device(&usb_bus);
 	return bus_register(&usb_bus_type);
 }
 pure_initcall(usb_bus_init);
diff --git a/include/usb/usb.h b/include/usb/usb.h
index 4649ee2..a0c26c1 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -193,6 +193,7 @@ struct usb_driver {
 	struct driver_d driver;
 };
 
+extern struct device_d usb_bus;
 extern struct bus_type usb_bus_type;
 
 int usb_driver_register(struct usb_driver *);
-- 
1.7.10.4


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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 09/12] fb: add bus device
  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
                     ` (6 preceding siblings ...)
  2012-10-14 21:01   ` [PATCH 08/12] usb: " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-14 21:01   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-14 21:01   ` [PATCH 10/12] mtd: register device a pure device Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 21:01 UTC (permalink / raw)
  To: barebox

automatically add it as parent of any fb device

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

diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index ee53272..0933a57 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -125,7 +125,10 @@ int register_framebuffer(struct fb_info *info)
 
 	sprintf(dev->name, "fb");
 
-	info->dev.bus = &fb_bus;
+	info->dev.bus = &fb_bus_type;
+	info->dev.parent = &fb_bus;
+	dev_add_child(info->dev.parent, &info->dev);
+
 	register_device(&info->dev);
 
 	return 0;
@@ -181,7 +184,12 @@ static void fb_remove(struct device_d *dev)
 {
 }
 
-struct bus_type fb_bus = {
+struct device_d fb_bus = {
+	.name = "fb",
+	.id = DEVICE_ID_SINGLE,
+};
+
+struct bus_type fb_bus_type = {
 	.name = "fb",
 	.match = fb_match,
 	.probe = fb_probe,
@@ -190,13 +198,14 @@ struct bus_type fb_bus = {
 
 static int fb_bus_init(void)
 {
-	return bus_register(&fb_bus);
+	register_device(&fb_bus);
+	return bus_register(&fb_bus_type);
 }
 pure_initcall(fb_bus_init);
 
 static int fb_init_driver(void)
 {
-	fb_driver.bus = &fb_bus;
+	fb_driver.bus = &fb_bus_type;
 	register_driver(&fb_driver);
 	return 0;
 }
diff --git a/include/fb.h b/include/fb.h
index c594418..9631733 100644
--- a/include/fb.h
+++ b/include/fb.h
@@ -110,7 +110,8 @@ int register_framebuffer(struct fb_info *info);
 #define	FBIO_ENABLE		_IO('F', 2)
 #define	FBIO_DISABLE		_IO('F', 3)
 
-extern struct bus_type fb_bus;
+extern struct device_d fb_bus;
+extern struct bus_type fb_bus_type;
 
 #endif /* __FB_H */
 
-- 
1.7.10.4


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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 10/12] mtd: register device a pure device
  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
                     ` (7 preceding siblings ...)
  2012-10-14 21:01   ` [PATCH 09/12] fb: " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-14 21:01   ` 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
  10 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 21:01 UTC (permalink / raw)
  To: barebox

as we do not need to probe them and they have no driver or bus attached

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/mtd/core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 7c323a1..a91ef04 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -225,7 +225,7 @@ int add_mtd_device(struct mtd_info *mtd, char *devname)
 		devname = "mtd";
 	strcpy(mtd->class_dev.name, devname);
 	mtd->class_dev.id = DEVICE_ID_DYNAMIC;
-	platform_device_register(&mtd->class_dev);
+	register_device(&mtd->class_dev);
 
 	mtd->cdev.ops = &mtd_ops;
 	mtd->cdev.size = mtd->size;
-- 
1.7.10.4


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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 11/12] mtd: add parent support
  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
                     ` (8 preceding siblings ...)
  2012-10-14 21:01   ` [PATCH 10/12] mtd: register device a pure device Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-14 21:01   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-14 21:01   ` [PATCH 12/12] eth: register device a pure device Jean-Christophe PLAGNIOL-VILLARD
  10 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 21:01 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/mtd/core.c                |    4 ++++
 drivers/mtd/devices/docg3.c       |    1 +
 drivers/mtd/nand/atmel_nand.c     |    1 +
 drivers/mtd/nand/nand_imx.c       |    2 +-
 drivers/mtd/nand/nand_mxs.c       |    1 +
 drivers/mtd/nand/nand_omap_gpmc.c |    1 +
 drivers/mtd/nand/nand_s3c24xx.c   |    1 +
 drivers/mtd/nand/nomadik_nand.c   |    1 +
 include/linux/mtd/mtd.h           |    2 +-
 9 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index a91ef04..94b7171 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -225,6 +225,10 @@ int add_mtd_device(struct mtd_info *mtd, char *devname)
 		devname = "mtd";
 	strcpy(mtd->class_dev.name, devname);
 	mtd->class_dev.id = DEVICE_ID_DYNAMIC;
+	if (mtd->parent) {
+		mtd->class_dev.parent = mtd->parent;
+		dev_add_child(mtd->class_dev.parent, &mtd->class_dev);
+	}
 	register_device(&mtd->class_dev);
 
 	mtd->cdev.ops = &mtd_ops;
diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
index 0fe6799..2f89900 100644
--- a/drivers/mtd/devices/docg3.c
+++ b/drivers/mtd/devices/docg3.c
@@ -1172,6 +1172,7 @@ static int __init docg3_probe(struct device_d *dev)
 				continue;
 		}
 		docg3_floors[floor] = mtd;
+		mtd->parent = dev;
 		ret = add_mtd_device(mtd, NULL);
 		if (ret)
 			goto err_probe;
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index aa01124..2784e39 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -363,6 +363,7 @@ static int __init atmel_nand_probe(struct device_d *dev)
 
 	nand_chip->priv = host;		/* link the private data structures */
 	mtd->priv = nand_chip;
+	mtd->parent = dev;
 
 	/* Set address of NAND IO lines */
 	nand_chip->IO_ADDR_R = host->io_base;
diff --git a/drivers/mtd/nand/nand_imx.c b/drivers/mtd/nand/nand_imx.c
index b1b7f55..0dcf34a 100644
--- a/drivers/mtd/nand/nand_imx.c
+++ b/drivers/mtd/nand/nand_imx.c
@@ -1182,7 +1182,7 @@ static int __init imxnd_probe(struct device_d *dev)
 	this = &host->nand;
 	mtd = &host->mtd;
 	mtd->priv = this;
-	mtd->dev = dev;
+	mtd->parent = dev;
 
 	/* 50 us command delay time */
 	this->chip_delay = 5;
diff --git a/drivers/mtd/nand/nand_mxs.c b/drivers/mtd/nand/nand_mxs.c
index 8aeb14d..d71983a 100644
--- a/drivers/mtd/nand/nand_mxs.c
+++ b/drivers/mtd/nand/nand_mxs.c
@@ -1201,6 +1201,7 @@ static int mxs_nand_probe(struct device_d *dev)
 	nand = &nand_info->nand_chip;
 	mtd = &nand_info->mtd;
 	mtd->priv = nand;
+	mtd->parent = dev;
 
 	nand->priv = nand_info;
 	nand->options |= NAND_NO_SUBPAGE_WRITE;
diff --git a/drivers/mtd/nand/nand_omap_gpmc.c b/drivers/mtd/nand/nand_omap_gpmc.c
index cc356f7..f4f5335 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -929,6 +929,7 @@ static int gpmc_nand_probe(struct device_d *pdev)
 
 	minfo = &oinfo->minfo;
 	minfo->priv = (void *)nand;
+	minfo->parent = dev;
 
 	if (pdata->cs >= GPMC_NUM_CS) {
 		dev_dbg(pdev, "Invalid CS!\n");
diff --git a/drivers/mtd/nand/nand_s3c24xx.c b/drivers/mtd/nand/nand_s3c24xx.c
index 12db692..aef7fa9 100644
--- a/drivers/mtd/nand/nand_s3c24xx.c
+++ b/drivers/mtd/nand/nand_s3c24xx.c
@@ -425,6 +425,7 @@ static int s3c24x0_nand_probe(struct device_d *dev)
 	chip = &host->nand;
 	mtd = &host->mtd;
 	mtd->priv = chip;
+	mtd->parent = dev;
 
 	/* init the default settings */
 
diff --git a/drivers/mtd/nand/nomadik_nand.c b/drivers/mtd/nand/nomadik_nand.c
index 6fc9398..d7e4ae5 100644
--- a/drivers/mtd/nand/nomadik_nand.c
+++ b/drivers/mtd/nand/nomadik_nand.c
@@ -197,6 +197,7 @@ static int nomadik_nand_probe(struct device_d *dev)
 	nand = &host->nand;
 	mtd->priv = nand;
 	nand->priv = host;
+	mtd->parent = dev;
 
 	nand->IO_ADDR_W = nand->IO_ADDR_R = dev_request_mem_region(dev, 2);
 	nand->cmd_ctrl = nomadik_cmd_ctrl;
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 71d3c6f..8114967 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -200,7 +200,7 @@ struct mtd_info {
 	void (*put_device) (struct mtd_info *mtd);
 
 	struct device_d class_dev;
-	struct device_d *dev;
+	struct device_d *parent;
 	struct cdev cdev;
 
 	struct param_d param_size;
-- 
1.7.10.4


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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 12/12] eth: register device a pure device
  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
                     ` (9 preceding siblings ...)
  2012-10-14 21:01   ` [PATCH 11/12] mtd: add parent support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-14 21:01   ` Jean-Christophe PLAGNIOL-VILLARD
  10 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14 21:01 UTC (permalink / raw)
  To: barebox

as we do not need to probe them and they have no driver or bus attached

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 net/eth.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/eth.c b/net/eth.c
index f3d7bfe..220edcf 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -261,7 +261,7 @@ int eth_register(struct eth_device *edev)
 	if (edev->parent)
 		dev_add_child(edev->parent, &edev->dev);
 
-	platform_device_register(&edev->dev);
+	register_device(&edev->dev);
 
 	dev_add_param(dev, "ipaddr", eth_set_ipaddr, NULL, 0);
 	dev_add_param(dev, "ethaddr", eth_set_ethaddr, NULL, 0);
-- 
1.7.10.4


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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 00/12] add bus device
  2012-10-14 20:59 [PATCH 00/12] add bus device 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-15  7:10 ` Sascha Hauer
  2012-10-15 10:23   ` Jean-Christophe PLAGNIOL-VILLARD
  1 sibling, 1 reply; 19+ messages in thread
From: Sascha Hauer @ 2012-10-15  7:10 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Sun, Oct 14, 2012 at 10:59:29PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Hi,
> 
> we have now a nice output per bus
> 
> barebox@ST SPEARr1340 EVB:/
> # devinfo 
> devices:
> `---- platfrom
>      `---- mem0
>           `---- 0x00000000-0x3fffffff: /dev/ram0
>      `---- smp_twd
>      `---- mem1
>           `---- 0x00000000-0x0000251f: /dev/defaultenv
>      `---- mem2
>           `---- 0x00000000-0xfffffffe: /dev/mem
>      `---- designware_eth0
>           `---- miibus0
>           `---- eth0
>      `---- fsmc-nand
>           `---- nand0
>                `---- 0x00000000-0x7fffffff: /dev/nand0
>                `---- 0x00000000-0x0000ffff: /dev/xloader
>                `---- 0x00010000-0x0004ffff: /dev/self_raw
>                `---- 0x00050000-0x0006ffff: /dev/env_raw
>                `---- 0x00000000-0x0003ffff: /dev/nand0.xloader
>                `---- 0x00040000-0x0007ffff: /dev/nand0.meminit
>                `---- 0x00080000-0x0027ffff: /dev/nand0.barebox
>                `---- 0x00280000-0x0057ffff: /dev/nand0.kernel
>                `---- 0x00580000-0x01b7ffff: /dev/nand0.rootfs
>                `---- 0x01b80000-0x07f7ffff: /dev/nand0.userfs
>                `---- 0x07f80000-0x07fdffff: /dev/nand0.free
>                `---- 0x07fe0000-0x07ffffff: /dev/nand0.bareboxenv
>      `---- smi
>           `---- smi0
>                `---- 0x00000000-0x007fffff: /dev/smi0
>      `---- sdhci-spear
>           `---- mci0
>                `---- 0x00000000-0x1e3dffff: /dev/disk0
>                `---- 0x0001da00-0x1e3d1fff: /dev/disk0.0
> `---- amba
>      `---- uart-pl0110
>           `---- cs0
>      `---- pl061_gpio0
>      `---- pl061_gpio1
>      `---- ssp-pl0220
>           `---- m25p0
>                `---- 0x00000000-0x0000ffff: /dev/m25p0
> `---- mdio_bus
> `---- usb
> `---- spi
> `---- i2c
> `---- fb
> `---- fs
>      `---- ramfs0
>      `---- devfs0
> `---- net
> `---- global

Look nice indeed. Why not do it simpler?


From f8e90176da267275fa25feca2b880cdf4d9f5daf Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer@pengutronix.de>
Date: Mon, 15 Oct 2012 08:53:29 +0200
Subject: [PATCH] add bus devices

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/base/bus.c    |    9 +++++++++
 drivers/base/driver.c |    5 +++++
 include/driver.h      |    2 ++
 3 files changed, 16 insertions(+)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 69782d2..caff0af 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -25,12 +25,21 @@ static struct bus_type *get_bus_by_name(const char *name)
 
 int bus_register(struct bus_type *bus)
 {
+	int ret;
+
 	if (get_bus_by_name(bus->name))
 		return -EEXIST;
 
 	INIT_LIST_HEAD(&bus->device_list);
 	INIT_LIST_HEAD(&bus->driver_list);
 
+	safe_strncpy(bus->bus_dev.name, bus->name, MAX_DRIVER_NAME);
+	bus->bus_dev.id = DEVICE_ID_SINGLE;
+
+	ret = register_device(&bus->bus_dev);
+	if (ret)
+		return ret;
+
 	list_add_tail(&bus->list, &bus_list);
 
 	return 0;
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 5b7286a..395546b 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -127,6 +127,11 @@ int register_device(struct device_d *new_device)
 
 	list_add_tail(&new_device->bus_list, &new_device->bus->device_list);
 
+	if (!new_device->parent) {
+		new_device->parent = &new_device->bus->dev;
+		dev_add_child(new_device->parent, new_device);
+	}
+
 	bus_for_each_driver(new_device->bus, drv) {
 		if (!match(drv, new_device))
 			break;
diff --git a/include/driver.h b/include/driver.h
index 4918054..100eb15 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -381,6 +381,8 @@ struct bus_type {
 	struct list_head list;
 	struct list_head device_list;
 	struct list_head driver_list;
+
+	struct device_d bus_dev;
 };
 
 int bus_register(struct bus_type *bus);
-- 
1.7.10.4


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 00/12] add bus device
  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
  0 siblings, 1 reply; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-15 10:23 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 09:10 Mon 15 Oct     , Sascha Hauer wrote:
> On Sun, Oct 14, 2012 at 10:59:29PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > Hi,
> > 
> > we have now a nice output per bus
> > 
> > barebox@ST SPEARr1340 EVB:/
> > # devinfo 
> > devices:
> > `---- platfrom
> >      `---- mem0
> >           `---- 0x00000000-0x3fffffff: /dev/ram0
> >      `---- smp_twd
> >      `---- mem1
> >           `---- 0x00000000-0x0000251f: /dev/defaultenv
> >      `---- mem2
> >           `---- 0x00000000-0xfffffffe: /dev/mem
> >      `---- designware_eth0
> >           `---- miibus0
> >           `---- eth0
> >      `---- fsmc-nand
> >           `---- nand0
> >                `---- 0x00000000-0x7fffffff: /dev/nand0
> >                `---- 0x00000000-0x0000ffff: /dev/xloader
> >                `---- 0x00010000-0x0004ffff: /dev/self_raw
> >                `---- 0x00050000-0x0006ffff: /dev/env_raw
> >                `---- 0x00000000-0x0003ffff: /dev/nand0.xloader
> >                `---- 0x00040000-0x0007ffff: /dev/nand0.meminit
> >                `---- 0x00080000-0x0027ffff: /dev/nand0.barebox
> >                `---- 0x00280000-0x0057ffff: /dev/nand0.kernel
> >                `---- 0x00580000-0x01b7ffff: /dev/nand0.rootfs
> >                `---- 0x01b80000-0x07f7ffff: /dev/nand0.userfs
> >                `---- 0x07f80000-0x07fdffff: /dev/nand0.free
> >                `---- 0x07fe0000-0x07ffffff: /dev/nand0.bareboxenv
> >      `---- smi
> >           `---- smi0
> >                `---- 0x00000000-0x007fffff: /dev/smi0
> >      `---- sdhci-spear
> >           `---- mci0
> >                `---- 0x00000000-0x1e3dffff: /dev/disk0
> >                `---- 0x0001da00-0x1e3d1fff: /dev/disk0.0
> > `---- amba
> >      `---- uart-pl0110
> >           `---- cs0
> >      `---- pl061_gpio0
> >      `---- pl061_gpio1
> >      `---- ssp-pl0220
> >           `---- m25p0
> >                `---- 0x00000000-0x0000ffff: /dev/m25p0
> > `---- mdio_bus
> > `---- usb
> > `---- spi
> > `---- i2c
> > `---- fb
> > `---- fs
> >      `---- ramfs0
> >      `---- devfs0
> > `---- net
> > `---- global
> 
> Look nice indeed. Why not do it simpler?
> 
> 
> From f8e90176da267275fa25feca2b880cdf4d9f5daf Mon Sep 17 00:00:00 2001
> From: Sascha Hauer <s.hauer@pengutronix.de>
> Date: Mon, 15 Oct 2012 08:53:29 +0200
> Subject: [PATCH] add bus devices
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/base/bus.c    |    9 +++++++++
>  drivers/base/driver.c |    5 +++++
>  include/driver.h      |    2 ++
>  3 files changed, 16 insertions(+)
> 
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> index 69782d2..caff0af 100644
> --- a/drivers/base/bus.c
> +++ b/drivers/base/bus.c
> @@ -25,12 +25,21 @@ static struct bus_type *get_bus_by_name(const char *name)
>  
>  int bus_register(struct bus_type *bus)
>  {
> +	int ret;
> +
>  	if (get_bus_by_name(bus->name))
>  		return -EEXIST;
>  
>  	INIT_LIST_HEAD(&bus->device_list);
>  	INIT_LIST_HEAD(&bus->driver_list);
>  
> +	safe_strncpy(bus->bus_dev.name, bus->name, MAX_DRIVER_NAME);
> +	bus->bus_dev.id = DEVICE_ID_SINGLE;
> +
> +	ret = register_device(&bus->bus_dev);
> +	if (ret)
> +		return ret;
> +
>  	list_add_tail(&bus->list, &bus_list);
>  
>  	return 0;
> diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> index 5b7286a..395546b 100644
> --- a/drivers/base/driver.c
> +++ b/drivers/base/driver.c
> @@ -127,6 +127,11 @@ int register_device(struct device_d *new_device)
>  
>  	list_add_tail(&new_device->bus_list, &new_device->bus->device_list);
>  
> +	if (!new_device->parent) {
> +		new_device->parent = &new_device->bus->dev;
> +		dev_add_child(new_device->parent, new_device);
and I was wanting to add global name "barebox" and add everyone under to it

I choose to do let the bus manage the child
and to create a device or not

as done in linux

Best Regards,
J.

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 00/12] add bus device
  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
  0 siblings, 1 reply; 19+ messages in thread
From: Sascha Hauer @ 2012-10-15 13:21 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Mon, Oct 15, 2012 at 12:23:07PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 09:10 Mon 15 Oct     , Sascha Hauer wrote:
> > +	ret = register_device(&bus->bus_dev);
> > +	if (ret)
> > +		return ret;
> > +
> >  	list_add_tail(&bus->list, &bus_list);
> >  
> >  	return 0;
> > diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> > index 5b7286a..395546b 100644
> > --- a/drivers/base/driver.c
> > +++ b/drivers/base/driver.c
> > @@ -127,6 +127,11 @@ int register_device(struct device_d *new_device)
> >  
> >  	list_add_tail(&new_device->bus_list, &new_device->bus->device_list);
> >  
> > +	if (!new_device->parent) {
> > +		new_device->parent = &new_device->bus->dev;
> > +		dev_add_child(new_device->parent, new_device);
> and I was wanting to add global name "barebox" and add everyone under to it
> 
> I choose to do let the bus manage the child
> and to create a device or not

Any idea why we would need this?

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 00/12] add bus device
  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
  0 siblings, 2 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-15 14:49 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 15:21 Mon 15 Oct     , Sascha Hauer wrote:
> On Mon, Oct 15, 2012 at 12:23:07PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 09:10 Mon 15 Oct     , Sascha Hauer wrote:
> > > +	ret = register_device(&bus->bus_dev);
> > > +	if (ret)
> > > +		return ret;
> > > +
> > >  	list_add_tail(&bus->list, &bus_list);
> > >  
> > >  	return 0;
> > > diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> > > index 5b7286a..395546b 100644
> > > --- a/drivers/base/driver.c
> > > +++ b/drivers/base/driver.c
> > > @@ -127,6 +127,11 @@ int register_device(struct device_d *new_device)
> > >  
> > >  	list_add_tail(&new_device->bus_list, &new_device->bus->device_list);
> > >  
> > > +	if (!new_device->parent) {
> > > +		new_device->parent = &new_device->bus->dev;
> > > +		dev_add_child(new_device->parent, new_device);
> > and I was wanting to add global name "barebox" and add everyone under to it
> > 
> > I choose to do let the bus manage the child
> > and to create a device or not
> 
> Any idea why we would need this?
mdio bus as example I was thinking to drop the device as they are always
attached to a ethernet device

input bus too

as example some bus as device specific so no need to add device as the device
is already here

I already implement this on arm and so it in the kernel arm too

Best Regards,
J.

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 00/12] add bus device
  2012-10-15 14:49       ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-15 19:09         ` Sascha Hauer
  2012-10-29 10:41         ` Sascha Hauer
  1 sibling, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2012-10-15 19:09 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Mon, Oct 15, 2012 at 04:49:35PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 15:21 Mon 15 Oct     , Sascha Hauer wrote:
> > > > --- a/drivers/base/driver.c
> > > > +++ b/drivers/base/driver.c
> > > > @@ -127,6 +127,11 @@ int register_device(struct device_d *new_device)
> > > >  
> > > >  	list_add_tail(&new_device->bus_list, &new_device->bus->device_list);
> > > >  
> > > > +	if (!new_device->parent) {
> > > > +		new_device->parent = &new_device->bus->dev;
> > > > +		dev_add_child(new_device->parent, new_device);
> > > and I was wanting to add global name "barebox" and add everyone under to it
> > > 
> > > I choose to do let the bus manage the child
> > > and to create a device or not
> > 
> > Any idea why we would need this?
> mdio bus as example I was thinking to drop the device as they are always
> attached to a ethernet device
> 
> input bus too
> 
> as example some bus as device specific so no need to add device as the device
> is already here
> 
> I already implement this on arm and so it in the kernel arm too

The patch only makes the new device a child of the bus device when no
parent is set, so it would still be possible to make the phy a child
of the ethernet device.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 00/12] add bus device
  2012-10-15 14:49       ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-15 19:09         ` Sascha Hauer
@ 2012-10-29 10:41         ` Sascha Hauer
  1 sibling, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2012-10-29 10:41 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Mon, Oct 15, 2012 at 04:49:35PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 15:21 Mon 15 Oct     , Sascha Hauer wrote:
> > On Mon, Oct 15, 2012 at 12:23:07PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > On 09:10 Mon 15 Oct     , Sascha Hauer wrote:
> > > > +	ret = register_device(&bus->bus_dev);
> > > > +	if (ret)
> > > > +		return ret;
> > > > +
> > > >  	list_add_tail(&bus->list, &bus_list);
> > > >  
> > > >  	return 0;
> > > > diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> > > > index 5b7286a..395546b 100644
> > > > --- a/drivers/base/driver.c
> > > > +++ b/drivers/base/driver.c
> > > > @@ -127,6 +127,11 @@ int register_device(struct device_d *new_device)
> > > >  
> > > >  	list_add_tail(&new_device->bus_list, &new_device->bus->device_list);
> > > >  
> > > > +	if (!new_device->parent) {
> > > > +		new_device->parent = &new_device->bus->dev;
> > > > +		dev_add_child(new_device->parent, new_device);
> > > and I was wanting to add global name "barebox" and add everyone under to it
> > > 
> > > I choose to do let the bus manage the child
> > > and to create a device or not
> > 
> > Any idea why we would need this?
> mdio bus as example I was thinking to drop the device as they are always
> attached to a ethernet device

They are not. drivers/net/ksz8864rmn.c for example is a switch driver
for which no ethernet device exists.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2012-10-29 10:41 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-14 20:59 [PATCH 00/12] add bus device 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   ` [PATCH 07/12] spi: " Jean-Christophe PLAGNIOL-VILLARD
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox