Re: [U-Boot] [PATCH v2 16/26] dm: core: Allow uclass to set up a device's child before it is probed

2015-01-22 Thread Masahiro Yamada

On Mon, 19 Jan 2015 20:12:45 -0700
Simon Glass s...@chromium.org wrote:

 Some buses need to set up their devices before they can be used. This setup
 may well be common to all buses in a particular uclass. Support a common
 pre-probe method for the uclass, called before any bus devices are probed.
 
 Signed-off-by: Simon Glass s...@chromium.org
 ---


Reviewed-by: Masahiro Yamada yamad...@jp.panasonic.com

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2 16/26] dm: core: Allow uclass to set up a device's child before it is probed

2015-01-19 Thread Simon Glass
Some buses need to set up their devices before they can be used. This setup
may well be common to all buses in a particular uclass. Support a common
pre-probe method for the uclass, called before any bus devices are probed.

Signed-off-by: Simon Glass s...@chromium.org
---

Changes in v2: None

 drivers/core/device.c|  4 
 drivers/core/uclass.c| 13 +
 include/dm/test.h|  3 +++
 include/dm/uclass-internal.h | 11 +++
 include/dm/uclass.h  |  1 +
 test/dm/bus.c| 46 
 test/dm/test-fdt.c   |  7 +++
 7 files changed, 85 insertions(+)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 2639fcb..b050272 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -227,6 +227,10 @@ int device_probe_child(struct udevice *dev, void 
*parent_priv)
}
dev-seq = seq;
 
+   ret = uclass_pre_probe_child(dev);
+   if (ret)
+   goto fail;
+
if (dev-parent  dev-parent-driver-child_pre_probe) {
ret = dev-parent-driver-child_pre_probe(dev);
if (ret)
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 29811be..8c91370 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -391,6 +391,19 @@ int uclass_resolve_seq(struct udevice *dev)
return seq;
 }
 
+int uclass_pre_probe_child(struct udevice *dev)
+{
+   struct uclass_driver *uc_drv;
+
+   if (!dev-parent)
+   return 0;
+   uc_drv = dev-parent-uclass-uc_drv;
+   if (uc_drv-child_pre_probe)
+   return uc_drv-child_pre_probe(dev);
+
+   return 0;
+}
+
 int uclass_post_probe_device(struct udevice *dev)
 {
struct uclass_driver *uc_drv = dev-uclass-uc_drv;
diff --git a/include/dm/test.h b/include/dm/test.h
index f08c05d..707c69e 100644
--- a/include/dm/test.h
+++ b/include/dm/test.h
@@ -67,6 +67,8 @@ enum {
 struct dm_test_priv {
int ping_total;
int op_count[DM_TEST_OP_COUNT];
+   int uclass_flag;
+   int uclass_total;
 };
 
 /**
@@ -88,6 +90,7 @@ struct dm_test_uclass_priv {
  *
  * @sum: Test value used to check parent data works correctly
  * @flag: Used to track calling of parent operations
+ * @uclass_flag: Used to track calling of parent operations by uclass
  */
 struct dm_test_parent_data {
int sum;
diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h
index f718f37..f2f254a 100644
--- a/include/dm/uclass-internal.h
+++ b/include/dm/uclass-internal.h
@@ -44,6 +44,17 @@ int uclass_bind_device(struct udevice *dev);
 int uclass_unbind_device(struct udevice *dev);
 
 /**
+ * uclass_pre_probe_child() - Deal with a child that is about to be probed
+ *
+ * Perform any pre-processing that is needed by the uclass before it can be
+ * probed.
+ *
+ * @dev:   Pointer to the device
+ * #return 0 on success, -ve on error
+ */
+int uclass_pre_probe_child(struct udevice *dev);
+
+/**
  * uclass_post_probe_device() - Deal with a device that has just been probed
  *
  * Perform any post-processing of a probed device that is needed by the
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 5c5b8f4..d6c40c6 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -83,6 +83,7 @@ struct uclass_driver {
int (*post_probe)(struct udevice *dev);
int (*pre_remove)(struct udevice *dev);
int (*child_post_bind)(struct udevice *dev);
+   int (*child_pre_probe)(struct udevice *dev);
int (*init)(struct uclass *class);
int (*destroy)(struct uclass *class);
int priv_auto_alloc_size;
diff --git a/test/dm/bus.c b/test/dm/bus.c
index c123ed7..faffe6a 100644
--- a/test/dm/bus.c
+++ b/test/dm/bus.c
@@ -53,6 +53,15 @@ static int testbus_child_pre_probe(struct udevice *dev)
return 0;
 }
 
+static int testbus_child_pre_probe_uclass(struct udevice *dev)
+{
+   struct dm_test_priv *priv = dev_get_priv(dev);
+
+   priv-uclass_flag++;
+
+   return 0;
+}
+
 static int testbus_child_post_remove(struct udevice *dev)
 {
struct dm_test_parent_data *parent_data = dev_get_parentdata(dev);
@@ -91,6 +100,7 @@ UCLASS_DRIVER(testbus) = {
.name   = testbus,
.id = UCLASS_TEST_BUS,
.flags  = DM_UC_FLAG_SEQ_ALIAS,
+   .child_pre_probe = testbus_child_pre_probe_uclass,
 };
 
 /* Test that we can probe for children */
@@ -469,3 +479,39 @@ static int dm_test_bus_child_post_bind_uclass(struct 
dm_test_state *dms)
 }
 DM_TEST(dm_test_bus_child_post_bind_uclass,
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/*
+ * Test that the bus' uclass' child_pre_probe() is called before the
+ * device's probe() method
+ */
+static int dm_test_bus_child_pre_probe_uclass(struct dm_test_state *dms)
+{
+   struct udevice *bus, *dev;
+   int child_count;
+
+   /*
+* See testfdt_drv_probe() which effectively checks that the