Skip to contentSkip to conversation

add bus device

PATCH Superseded Jean-Christophe PLAGNIOL-VILLARD 2 participants 19 messages Oct 14, 2012 – Oct 29, 2012

Subsystems (16)
Networking Network drivers VFS USB +12 more subsystems

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover add bus device

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

----------------------------------------------------------------
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH 1/12 bus_for_each_device/bus_for_each_driver: add () to allow use &bus

---
 include/driver.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/driver.h +2 -2
index 4918054..dd22c77 100644
@@ -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;
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/12 platform: add bus device

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

---
 drivers/base/platform.c |   18 ++++++++++++++----
 include/driver.h        |    3 ++-
 2 files changed, 16 insertions(+), 5 deletions(-)
drivers/base/platform.c +14 -4
index ea4e37b..08787f6 100644
@@ -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);
include/driver.h +2 -1
index dd22c77..5d85c1d 100644
@@ -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);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 3/12 amba: add bus device

In reply to Jean-Christophe PLAGNIOL-VILLARD

automatically add amba_device as parent of any amba device

---
 drivers/amba/bus.c |    8 ++++++++
 1 file changed, 8 insertions(+)
drivers/amba/bus.c +8 -0
index f0a40b6..581a25c 100644
@@ -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);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH 4/12 fs: add bus device

In reply to Jean-Christophe PLAGNIOL-VILLARD

automatically add it as parent of any fs device

---
 fs/fs.c |   23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
fs/fs.c +15 -8
index b9a1f17..b63a005 100644
@@ -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;
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH 5/12 mdio: add bus device

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 drivers/net/phy/mdio_bus.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/phy/mdio_bus.c +6 -0
index b49f714..eba3e1f 100644
@@ -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);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH 6/12 i2c: add bus device

In reply to Jean-Christophe PLAGNIOL-VILLARD

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

---
 drivers/i2c/i2c.c |   26 +++++++++++++++++++-------
 include/i2c/i2c.h |    5 +++--
 2 files changed, 22 insertions(+), 9 deletions(-)
drivers/i2c/i2c.c +19 -7
index 27fd256..dd7dfd7 100644
@@ -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);
include/i2c/i2c.h +3 -2
index de2a7ea..20d7f65 100644
@@ -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);
 }
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH 7/12 spi: add bus device

In reply to Jean-Christophe PLAGNIOL-VILLARD

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

---
 drivers/spi/spi.c |   17 ++++++++++++++---
 include/spi/spi.h |    5 +++--
 2 files changed, 17 insertions(+), 5 deletions(-)
drivers/spi/spi.c +14 -3
index 44040e5..51892a7 100644
@@ -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);
include/spi/spi.h +3 -2
index 1773ca2..fe9c809 100644
@@ -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);
 }
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH 8/12 usb: add bus device

In reply to Jean-Christophe PLAGNIOL-VILLARD

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

---
 drivers/usb/core/usb.c |   11 +++++++++++
 include/usb/usb.h      |    1 +
 2 files changed, 12 insertions(+)
drivers/usb/core/usb.c +11 -0
index 9dc931b..0d610d6 100644
@@ -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);
include/usb/usb.h +1 -0
index 4649ee2..a0c26c1 100644
@@ -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 *);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH 9/12 fb: add bus device

In reply to Jean-Christophe PLAGNIOL-VILLARD

automatically add it as parent of any fb device

---
 drivers/video/fb.c |   17 +++++++++++++----
 include/fb.h       |    3 ++-
 2 files changed, 15 insertions(+), 5 deletions(-)
drivers/video/fb.c +13 -4
index ee53272..0933a57 100644
@@ -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;
 }
include/fb.h +2 -1
index c594418..9631733 100644
@@ -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 */
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

PATCH 10/12 mtd: register device a pure device

In reply to Jean-Christophe PLAGNIOL-VILLARD

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

---
 drivers/mtd/core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/core.c +1 -1
index 7c323a1..a91ef04 100644
@@ -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;
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw

PATCH 11/12 mtd: add parent support

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 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(-)
drivers/mtd/core.c +4 -0
index a91ef04..94b7171 100644
@@ -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;
drivers/mtd/devices/docg3.c +1 -0
index 0fe6799..2f89900 100644
@@ -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;
drivers/mtd/nand/atmel_nand.c +1 -0
index aa01124..2784e39 100644
@@ -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;
drivers/mtd/nand/nand_imx.c +1 -1
index b1b7f55..0dcf34a 100644
@@ -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;
drivers/mtd/nand/nand_mxs.c +1 -0
index 8aeb14d..d71983a 100644
@@ -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;
drivers/mtd/nand/nand_omap_gpmc.c +1 -0
index cc356f7..f4f5335 100644
@@ -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");
drivers/mtd/nand/nand_s3c24xx.c +1 -0
index 12db692..aef7fa9 100644
@@ -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 */
 
drivers/mtd/nand/nomadik_nand.c +1 -0
index 6fc9398..d7e4ae5 100644
@@ -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;
include/linux/mtd/mtd.h +1 -1
index 71d3c6f..8114967 100644
@@ -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;
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#12 lore raw

PATCH 12/12 eth: register device a pure device

In reply to Jean-Christophe PLAGNIOL-VILLARD

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

---
 net/eth.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/eth.c +1 -1
index f3d7bfe..220edcf 100644
@@ -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);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#13 lore raw
In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 49 lines · Jean-Christophe PLAGNIOL-VILLARD

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
Quoted 8 lines
`---- 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 <[email protected]>
Date: Mon, 15 Oct 2012 08:53:29 +0200
Subject: [PATCH] add bus devices

---
 drivers/base/bus.c    |    9 +++++++++
 drivers/base/driver.c |    5 +++++
 include/driver.h      |    2 ++
 3 files changed, 16 insertions(+)
drivers/base/bus.c +9 -0
index 69782d2..caff0af 100644
@@ -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;
drivers/base/driver.c +5 -0
index 5b7286a..395546b 100644
@@ -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;
include/driver.h +2 -0
index 4918054..100eb15 100644
@@ -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);
Signature · 13 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#14 lore raw
Quoted 105 lines · Sascha Hauer
Quoted 49 lines · Jean-Christophe PLAGNIOL-VILLARD

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
Quoted 8 lines
`---- 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 <[email protected]>
Date: Mon, 15 Oct 2012 08:53:29 +0200
Subject: [PATCH] add bus devices

---
 drivers/base/bus.c    |    9 +++++++++
 drivers/base/driver.c |    5 +++++
 include/driver.h      |    2 ++
 3 files changed, 16 insertions(+)
drivers/base/bus.c +9 -0
index 69782d2..caff0af 100644
@@ -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;
drivers/base/driver.c +0 -0
index 5b7286a..395546b 100644

drivers/base/driver.c int register_device(struct device_d *new_device) · line 132

Quoted 6 lines
drivers/base/driver.c +3 -0
@@ -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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

maintainer
#15 lore raw
Quoted 16 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 15 lines · Sascha Hauer
drivers/base/bus.c +4 -0
+	ret = register_device(&bus->bus_dev);
+	if (ret)
+		return ret;
+
 	list_add_tail(&bus->list, &bus_list);
 
 	return 0;
drivers/base/driver.c +0 -0
index 5b7286a..395546b 100644
@@ -127,6 +127,11 @@ int register_device(struct device_d *new_device)
 
 	list_add_tail(&new_device->bus_list, &new_device->bus->device_list);
 
Quoted 7 lines

drivers/base/driver.c int register_device(struct device_d *new_device) · line 132

Quoted 3 lines
drivers/base/driver.c +3 -0
+	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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#16 lore raw
Quoted 22 lines · Sascha Hauer
Quoted 21 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 12 lines · Sascha Hauer
drivers/base/bus.c +4 -0
+	ret = register_device(&bus->bus_dev);
+	if (ret)
+		return ret;
+
 	list_add_tail(&bus->list, &bus_list);
 
 	return 0;
drivers/base/driver.c +0 -0
index 5b7286a..395546b 100644

drivers/base/driver.c int register_device(struct device_d *new_device) · line 132

Quoted 6 lines
drivers/base/driver.c +3 -0
@@ -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

Quoted 4 lines
Quoted 2 lines

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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

maintainer
#17 lore raw
Quoted 19 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 11 lines · Sascha Hauer
Quoted 11 lines

drivers/base/driver.c int register_device(struct device_d *new_device) · line 132

Quoted 9 lines
drivers/base/driver.c +3 -0
@@ -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

Quoted 4 lines
Quoted 2 lines

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

Quoted 6 lines

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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#18 lore raw
In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 23 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 22 lines · Sascha Hauer
Quoted 21 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 12 lines · Sascha Hauer
drivers/base/bus.c +4 -0
+	ret = register_device(&bus->bus_dev);
+	if (ret)
+		return ret;
+
 	list_add_tail(&bus->list, &bus_list);
 
 	return 0;
drivers/base/driver.c +0 -0
index 5b7286a..395546b 100644

drivers/base/driver.c int register_device(struct device_d *new_device) · line 132

Quoted 6 lines
drivers/base/driver.c +3 -0
@@ -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

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox