Re: [U-Boot] [PATCH v2 08/26] dm: core: Allow uclasses to specific the platdata for a device's children

2015-01-22 Thread Masahiro Yamada
Hi Simon,


The subject

dm: core: Allow uclasses to specific the platdata for a device's children


Maybe a typo,  s/specific/specify/
although English is slightly out of my realm...



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

 In many cases the child platform data for a device's children is defined by
 the uclass rather than the individual devices. For example, a SPI bus needs
 to know the chip select and speed for each of its children. It makes sense
 to allow this information to be defined the SPI uclass rather than each
 individual driver.
 
 If the device provides a size value for its child platdata, then use it.
 Failng that, fall back to that provided by the uclass.
 
 Signed-off-by: Simon Glass s...@chromium.org
 ---


The code looks good, so,

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 08/26] dm: core: Allow uclasses to specific the platdata for a device's children

2015-01-19 Thread Simon Glass
In many cases the child platform data for a device's children is defined by
the uclass rather than the individual devices. For example, a SPI bus needs
to know the chip select and speed for each of its children. It makes sense
to allow this information to be defined the SPI uclass rather than each
individual driver.

If the device provides a size value for its child platdata, then use it.
Failng that, fall back to that provided by the uclass.

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

Changes in v2: None

 drivers/core/device.c |  4 
 include/dm/uclass.h   |  5 +
 test/dm/bus.c | 32 ++--
 3 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 0682e2e..8791688 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -83,6 +83,10 @@ int device_bind(struct udevice *parent, struct driver *drv, 
const char *name,
if (parent  !dev-parent_platdata) {
int size = parent-driver-per_child_platdata_auto_alloc_size;
 
+   if (!size) {
+   size = parent-uclass-uc_drv-
+   per_child_platdata_auto_alloc_size;
+   }
if (size) {
dev-flags |= DM_FLAG_ALLOC_PARENT_PDATA;
dev-parent_platdata = calloc(1, size);
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 2577ae6..7d92d34 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -60,6 +60,10 @@ struct udevice;
  * @per_device_auto_alloc_size: Each device can hold private data owned
  * by the uclass. If required this will be automatically allocated if this
  * value is non-zero.
+ * @per_child_platdata_auto_alloc_size: A bus likes to store information about
+ * its children. If non-zero this is the size of this data, to be allocated
+ * in the child device's parent_platdata pointer. This value is only used as
+ * a falback if this member is 0 in the driver.
  * @ops: Uclass operations, providing the consistent interface to devices
  * within the uclass.
  */
@@ -74,6 +78,7 @@ struct uclass_driver {
int (*destroy)(struct uclass *class);
int priv_auto_alloc_size;
int per_device_auto_alloc_size;
+   int per_child_platdata_auto_alloc_size;
const void *ops;
 };
 
diff --git a/test/dm/bus.c b/test/dm/bus.c
index 63c8a9f..26b8293 100644
--- a/test/dm/bus.c
+++ b/test/dm/bus.c
@@ -279,8 +279,7 @@ static int dm_test_bus_parent_ops(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_bus_parent_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-/* Test that the bus can store platform data about each child */
-static int dm_test_bus_parent_platdata(struct dm_test_state *dms)
+static int test_bus_parent_platdata(struct dm_test_state *dms)
 {
struct dm_test_parent_platdata *plat;
struct udevice *bus, *dev;
@@ -351,4 +350,33 @@ static int dm_test_bus_parent_platdata(struct 
dm_test_state *dms)
 
return 0;
 }
+
+/* Test that the bus can store platform data about each child */
+static int dm_test_bus_parent_platdata(struct dm_test_state *dms)
+{
+   return test_bus_parent_platdata(dms);
+}
 DM_TEST(dm_test_bus_parent_platdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* As above but the size is controlled by the uclass */
+static int dm_test_bus_parent_platdata_uclass(struct dm_test_state *dms)
+{
+   struct udevice *bus;
+   int size;
+   int ret;
+
+   /* Set the driver size to 0 so that the uclass size is used */
+   ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, bus));
+   size = bus-driver-per_child_platdata_auto_alloc_size;
+   bus-uclass-uc_drv-per_child_platdata_auto_alloc_size = size;
+   bus-driver-per_child_platdata_auto_alloc_size = 0;
+   ret = test_bus_parent_platdata(dms);
+   if (ret)
+   return ret;
+   bus-uclass-uc_drv-per_child_platdata_auto_alloc_size = 0;
+   bus-driver-per_child_platdata_auto_alloc_size = size;
+
+   return 0;
+}
+DM_TEST(dm_test_bus_parent_platdata_uclass,
+   DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.2.0.rc0.207.ga3a616c

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