* [U-Boot] [PATCH 0/2] dm: core: add device's uclass platform data and tests
@ 2015-04-08 13:01 Przemyslaw Marczak
2015-04-08 13:01 ` [U-Boot] [PATCH 1/2] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak
` (2 more replies)
0 siblings, 3 replies; 61+ messages in thread
From: Przemyslaw Marczak @ 2015-04-08 13:01 UTC (permalink / raw)
To: u-boot
The struct udevice provides two fields for device's platform data:
- .platdata - to keep platform dependent data for the device driver
- .parent_platdata - to keep platform dependent data for the device parent
Some implementations may need addidional platform data, which could be owned
by the uclass. For example, the regulator device's constraints.
Two tests are added to the test framework:
- one for check dev->uclass_platdata pointer
- second for validation the data assigned to by test uclass's post_bind() method
At present there is an issue with running the full dm test, but the test for
device's uclass_platdata pass.
Przemyslaw Marczak (2):
dm: core: Extend struct udevice by '.uclass_platdata' field.
dm: test: Add tests for device's uclass platform data
drivers/core/device-remove.c | 4 ++++
drivers/core/device.c | 33 ++++++++++++++++++++++----
include/dm/device.h | 17 +++++++++++++-
include/dm/test.h | 20 ++++++++++++++++
include/dm/uclass.h | 4 ++++
test/dm/core.c | 55 ++++++++++++++++++++++++++++++++++++++++++++
test/dm/test-uclass.c | 11 +++++++++
7 files changed, 139 insertions(+), 5 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 61+ messages in thread* [U-Boot] [PATCH 1/2] dm: core: Extend struct udevice by '.uclass_platdata' field. 2015-04-08 13:01 [U-Boot] [PATCH 0/2] dm: core: add device's uclass platform data and tests Przemyslaw Marczak @ 2015-04-08 13:01 ` Przemyslaw Marczak 2015-04-08 13:47 ` Simon Glass 2015-04-08 13:01 ` [U-Boot] [PATCH 2/2] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak 2015-04-08 15:32 ` [U-Boot] [PATCH V2 0/3] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 2 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 13:01 UTC (permalink / raw) To: u-boot This commit adds 'uclass_platdata' field to 'struct udevice', which can be automatically allocated at bind. The allocation size is defined in 'struct uclass_driver' as 'per_device_platdata_auto_alloc_size'. New device's flag is added: DM_FLAG_ALLOC_UCLASS_PDATA, which is used for memory freeing at device unbind method. As for other udevice's fields, a complementary function is added: - dev_get_uclass_platdata() Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- drivers/core/device-remove.c | 4 ++++ drivers/core/device.c | 33 +++++++++++++++++++++++++++++---- include/dm/device.h | 17 ++++++++++++++++- include/dm/uclass.h | 4 ++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 7fee1c0..6a16b4f 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -92,6 +92,10 @@ int device_unbind(struct udevice *dev) free(dev->platdata); dev->platdata = NULL; } + if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { + free(dev->uclass_platdata); + dev->uclass_platdata = NULL; + } if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { free(dev->parent_platdata); dev->parent_platdata = NULL; diff --git a/drivers/core/device.c b/drivers/core/device.c index ccaa99c..c93141b 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -30,7 +30,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, { struct udevice *dev; struct uclass *uc; - int ret = 0; + int size = 0, ret = 0; *devp = NULL; if (!name) @@ -79,9 +79,19 @@ int device_bind(struct udevice *parent, const struct driver *drv, goto fail_alloc1; } } - if (parent) { - int size = parent->driver->per_child_platdata_auto_alloc_size; + size = uc->uc_drv->per_device_platdata_auto_alloc_size; + if (size) { + dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA; + dev->uclass_platdata = calloc(1, size); + if (!dev->uclass_platdata) { + ret = -ENOMEM; + goto fail_alloc2; + } + } + + if (parent) { + size = parent->driver->per_child_platdata_auto_alloc_size; if (!size) { size = parent->uclass->uc_drv-> per_child_platdata_auto_alloc_size; @@ -91,7 +101,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, dev->parent_platdata = calloc(1, size); if (!dev->parent_platdata) { ret = -ENOMEM; - goto fail_alloc2; + goto fail_alloc3; } } } @@ -139,6 +149,11 @@ fail_uclass_bind: free(dev->parent_platdata); dev->parent_platdata = NULL; } +fail_alloc3: + if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { + free(dev->uclass_platdata); + dev->uclass_platdata = NULL; + } fail_alloc2: if (dev->flags & DM_FLAG_ALLOC_PDATA) { free(dev->platdata); @@ -314,6 +329,16 @@ void *dev_get_parent_platdata(struct udevice *dev) return dev->parent_platdata; } +void *dev_get_uclass_platdata(struct udevice *dev) +{ + if (!dev) { + dm_warn("%s: null device", __func__); + return NULL; + } + + return dev->uclass_platdata; +} + void *dev_get_priv(struct udevice *dev) { if (!dev) { diff --git a/include/dm/device.h b/include/dm/device.h index c11342c..ad002fe 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -30,8 +30,11 @@ struct driver_info; /* DM is responsible for allocating and freeing parent_platdata */ #define DM_FLAG_ALLOC_PARENT_PDATA (1 << 3) +/* DM is responsible for allocating and freeing uclass_platdata */ +#define DM_FLAG_ALLOC_UCLASS_PDATA (1 << 4) + /* Allocate driver private data on a DMA boundary */ -#define DM_FLAG_ALLOC_PRIV_DMA (1 << 4) +#define DM_FLAG_ALLOC_PRIV_DMA (1 << 5) /** * struct udevice - An instance of a driver @@ -54,6 +57,7 @@ struct driver_info; * @name: Name of device, typically the FDT node name * @platdata: Configuration data for this device * @parent_platdata: The parent bus's configuration data for this device + * @uclass_platdata: The uclass's configuration data for this device * @of_offset: Device tree node offset for this device (- for none) * @driver_data: Driver data word for the entry that matched this device with * its driver @@ -75,6 +79,7 @@ struct udevice { const char *name; void *platdata; void *parent_platdata; + void *uclass_platdata; int of_offset; ulong driver_data; struct udevice *parent; @@ -210,6 +215,16 @@ void *dev_get_platdata(struct udevice *dev); void *dev_get_parent_platdata(struct udevice *dev); /** + * dev_get_uclass_platdata() - Get the uclass platform data for a device + * + * This checks that dev is not NULL, but no other checks for now + * + * @dev Device to check + * @return uclass's platform data, or NULL if none + */ +void *dev_get_uclass_platdata(struct udevice *dev); + +/** * dev_get_parentdata() - Get the parent data for a device * * The parent data is data stored in the device but owned by the parent. diff --git a/include/dm/uclass.h b/include/dm/uclass.h index d57d804..b271472 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -65,6 +65,9 @@ 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_device_platdata_auto_alloc_size: Each device can hold platform data + * owned by the uclass as 'dev->uclass_platdata'. If the value is non-zero, + * then this will be automatically allocated. * @per_child_auto_alloc_size: Each child device (of a parent in this * uclass) can hold parent data for the device/uclass. This value is only * used as a falback if this member is 0 in the driver. @@ -90,6 +93,7 @@ struct uclass_driver { int (*destroy)(struct uclass *class); int priv_auto_alloc_size; int per_device_auto_alloc_size; + int per_device_platdata_auto_alloc_size; int per_child_auto_alloc_size; int per_child_platdata_auto_alloc_size; const void *ops; -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH 1/2] dm: core: Extend struct udevice by '.uclass_platdata' field. 2015-04-08 13:01 ` [U-Boot] [PATCH 1/2] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak @ 2015-04-08 13:47 ` Simon Glass 2015-04-08 13:56 ` Przemyslaw Marczak 0 siblings, 1 reply; 61+ messages in thread From: Simon Glass @ 2015-04-08 13:47 UTC (permalink / raw) To: u-boot Hi Przemyslaw, On 8 April 2015 at 07:01, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit adds 'uclass_platdata' field to 'struct udevice', which > can be automatically allocated at bind. The allocation size is defined > in 'struct uclass_driver' as 'per_device_platdata_auto_alloc_size'. > > New device's flag is added: DM_FLAG_ALLOC_UCLASS_PDATA, which is used > for memory freeing at device unbind method. > > As for other udevice's fields, a complementary function is added: > - dev_get_uclass_platdata() > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > drivers/core/device-remove.c | 4 ++++ > drivers/core/device.c | 33 +++++++++++++++++++++++++++++---- > include/dm/device.h | 17 ++++++++++++++++- > include/dm/uclass.h | 4 ++++ > 4 files changed, 53 insertions(+), 5 deletions(-) Acked-by: Simon Glass <sjg@chromium.org> (one nit below) > > diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c > index 7fee1c0..6a16b4f 100644 > --- a/drivers/core/device-remove.c > +++ b/drivers/core/device-remove.c > @@ -92,6 +92,10 @@ int device_unbind(struct udevice *dev) > free(dev->platdata); > dev->platdata = NULL; > } > + if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { > + free(dev->uclass_platdata); > + dev->uclass_platdata = NULL; > + } > if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { > free(dev->parent_platdata); > dev->parent_platdata = NULL; > diff --git a/drivers/core/device.c b/drivers/core/device.c > index ccaa99c..c93141b 100644 > --- a/drivers/core/device.c > +++ b/drivers/core/device.c > @@ -30,7 +30,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, > { > struct udevice *dev; > struct uclass *uc; > - int ret = 0; > + int size = 0, ret = 0; nit: I don't think you need = 0 on size. > > *devp = NULL; > if (!name) > @@ -79,9 +79,19 @@ int device_bind(struct udevice *parent, const struct driver *drv, > goto fail_alloc1; > } > } > - if (parent) { > - int size = parent->driver->per_child_platdata_auto_alloc_size; > > + size = uc->uc_drv->per_device_platdata_auto_alloc_size; > + if (size) { > + dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA; > + dev->uclass_platdata = calloc(1, size); > + if (!dev->uclass_platdata) { > + ret = -ENOMEM; > + goto fail_alloc2; > + } > + } > + > + if (parent) { > + size = parent->driver->per_child_platdata_auto_alloc_size; > if (!size) { > size = parent->uclass->uc_drv-> > per_child_platdata_auto_alloc_size; > @@ -91,7 +101,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, > dev->parent_platdata = calloc(1, size); > if (!dev->parent_platdata) { > ret = -ENOMEM; > - goto fail_alloc2; > + goto fail_alloc3; > } > } > } > @@ -139,6 +149,11 @@ fail_uclass_bind: > free(dev->parent_platdata); > dev->parent_platdata = NULL; > } > +fail_alloc3: > + if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { > + free(dev->uclass_platdata); > + dev->uclass_platdata = NULL; > + } > fail_alloc2: > if (dev->flags & DM_FLAG_ALLOC_PDATA) { > free(dev->platdata); > @@ -314,6 +329,16 @@ void *dev_get_parent_platdata(struct udevice *dev) > return dev->parent_platdata; > } > > +void *dev_get_uclass_platdata(struct udevice *dev) > +{ > + if (!dev) { > + dm_warn("%s: null device", __func__); > + return NULL; > + } > + > + return dev->uclass_platdata; > +} > + > void *dev_get_priv(struct udevice *dev) > { > if (!dev) { > diff --git a/include/dm/device.h b/include/dm/device.h > index c11342c..ad002fe 100644 > --- a/include/dm/device.h > +++ b/include/dm/device.h > @@ -30,8 +30,11 @@ struct driver_info; > /* DM is responsible for allocating and freeing parent_platdata */ > #define DM_FLAG_ALLOC_PARENT_PDATA (1 << 3) > > +/* DM is responsible for allocating and freeing uclass_platdata */ > +#define DM_FLAG_ALLOC_UCLASS_PDATA (1 << 4) > + > /* Allocate driver private data on a DMA boundary */ > -#define DM_FLAG_ALLOC_PRIV_DMA (1 << 4) > +#define DM_FLAG_ALLOC_PRIV_DMA (1 << 5) > > /** > * struct udevice - An instance of a driver > @@ -54,6 +57,7 @@ struct driver_info; > * @name: Name of device, typically the FDT node name > * @platdata: Configuration data for this device > * @parent_platdata: The parent bus's configuration data for this device > + * @uclass_platdata: The uclass's configuration data for this device > * @of_offset: Device tree node offset for this device (- for none) > * @driver_data: Driver data word for the entry that matched this device with > * its driver > @@ -75,6 +79,7 @@ struct udevice { > const char *name; > void *platdata; > void *parent_platdata; > + void *uclass_platdata; > int of_offset; > ulong driver_data; > struct udevice *parent; > @@ -210,6 +215,16 @@ void *dev_get_platdata(struct udevice *dev); > void *dev_get_parent_platdata(struct udevice *dev); > > /** > + * dev_get_uclass_platdata() - Get the uclass platform data for a device > + * > + * This checks that dev is not NULL, but no other checks for now > + * > + * @dev Device to check > + * @return uclass's platform data, or NULL if none > + */ > +void *dev_get_uclass_platdata(struct udevice *dev); > + > +/** > * dev_get_parentdata() - Get the parent data for a device > * > * The parent data is data stored in the device but owned by the parent. > diff --git a/include/dm/uclass.h b/include/dm/uclass.h > index d57d804..b271472 100644 > --- a/include/dm/uclass.h > +++ b/include/dm/uclass.h > @@ -65,6 +65,9 @@ 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_device_platdata_auto_alloc_size: Each device can hold platform data > + * owned by the uclass as 'dev->uclass_platdata'. If the value is non-zero, > + * then this will be automatically allocated. > * @per_child_auto_alloc_size: Each child device (of a parent in this > * uclass) can hold parent data for the device/uclass. This value is only > * used as a falback if this member is 0 in the driver. > @@ -90,6 +93,7 @@ struct uclass_driver { > int (*destroy)(struct uclass *class); > int priv_auto_alloc_size; > int per_device_auto_alloc_size; > + int per_device_platdata_auto_alloc_size; > int per_child_auto_alloc_size; > int per_child_platdata_auto_alloc_size; > const void *ops; > -- > 1.9.1 > Regards, Simon ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH 1/2] dm: core: Extend struct udevice by '.uclass_platdata' field. 2015-04-08 13:47 ` Simon Glass @ 2015-04-08 13:56 ` Przemyslaw Marczak 0 siblings, 0 replies; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 13:56 UTC (permalink / raw) To: u-boot Hello, On 04/08/2015 03:47 PM, Simon Glass wrote: > Hi Przemyslaw, > > On 8 April 2015 at 07:01, Przemyslaw Marczak <p.marczak@samsung.com> wrote: >> This commit adds 'uclass_platdata' field to 'struct udevice', which >> can be automatically allocated at bind. The allocation size is defined >> in 'struct uclass_driver' as 'per_device_platdata_auto_alloc_size'. >> >> New device's flag is added: DM_FLAG_ALLOC_UCLASS_PDATA, which is used >> for memory freeing at device unbind method. >> >> As for other udevice's fields, a complementary function is added: >> - dev_get_uclass_platdata() >> >> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> >> Cc: Simon Glass <sjg@chromium.org> >> --- >> drivers/core/device-remove.c | 4 ++++ >> drivers/core/device.c | 33 +++++++++++++++++++++++++++++---- >> include/dm/device.h | 17 ++++++++++++++++- >> include/dm/uclass.h | 4 ++++ >> 4 files changed, 53 insertions(+), 5 deletions(-) > > Acked-by: Simon Glass <sjg@chromium.org> > > (one nit below) > >> >> diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c >> index 7fee1c0..6a16b4f 100644 >> --- a/drivers/core/device-remove.c >> +++ b/drivers/core/device-remove.c >> @@ -92,6 +92,10 @@ int device_unbind(struct udevice *dev) >> free(dev->platdata); >> dev->platdata = NULL; >> } >> + if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { >> + free(dev->uclass_platdata); >> + dev->uclass_platdata = NULL; >> + } >> if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { >> free(dev->parent_platdata); >> dev->parent_platdata = NULL; >> diff --git a/drivers/core/device.c b/drivers/core/device.c >> index ccaa99c..c93141b 100644 >> --- a/drivers/core/device.c >> +++ b/drivers/core/device.c >> @@ -30,7 +30,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, >> { >> struct udevice *dev; >> struct uclass *uc; >> - int ret = 0; >> + int size = 0, ret = 0; > > nit: I don't think you need = 0 on size. > Ok, will fix. >> >> *devp = NULL; >> if (!name) >> @@ -79,9 +79,19 @@ int device_bind(struct udevice *parent, const struct driver *drv, >> goto fail_alloc1; >> } >> } >> - if (parent) { >> - int size = parent->driver->per_child_platdata_auto_alloc_size; >> >> + size = uc->uc_drv->per_device_platdata_auto_alloc_size; >> + if (size) { >> + dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA; >> + dev->uclass_platdata = calloc(1, size); >> + if (!dev->uclass_platdata) { >> + ret = -ENOMEM; >> + goto fail_alloc2; >> + } >> + } >> + >> + if (parent) { >> + size = parent->driver->per_child_platdata_auto_alloc_size; >> if (!size) { >> size = parent->uclass->uc_drv-> >> per_child_platdata_auto_alloc_size; >> @@ -91,7 +101,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, >> dev->parent_platdata = calloc(1, size); >> if (!dev->parent_platdata) { >> ret = -ENOMEM; >> - goto fail_alloc2; >> + goto fail_alloc3; >> } >> } >> } >> @@ -139,6 +149,11 @@ fail_uclass_bind: >> free(dev->parent_platdata); >> dev->parent_platdata = NULL; >> } >> +fail_alloc3: >> + if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { >> + free(dev->uclass_platdata); >> + dev->uclass_platdata = NULL; >> + } >> fail_alloc2: >> if (dev->flags & DM_FLAG_ALLOC_PDATA) { >> free(dev->platdata); >> @@ -314,6 +329,16 @@ void *dev_get_parent_platdata(struct udevice *dev) >> return dev->parent_platdata; >> } >> >> +void *dev_get_uclass_platdata(struct udevice *dev) >> +{ >> + if (!dev) { >> + dm_warn("%s: null device", __func__); >> + return NULL; >> + } >> + >> + return dev->uclass_platdata; >> +} >> + >> void *dev_get_priv(struct udevice *dev) >> { >> if (!dev) { >> diff --git a/include/dm/device.h b/include/dm/device.h >> index c11342c..ad002fe 100644 >> --- a/include/dm/device.h >> +++ b/include/dm/device.h >> @@ -30,8 +30,11 @@ struct driver_info; >> /* DM is responsible for allocating and freeing parent_platdata */ >> #define DM_FLAG_ALLOC_PARENT_PDATA (1 << 3) >> >> +/* DM is responsible for allocating and freeing uclass_platdata */ >> +#define DM_FLAG_ALLOC_UCLASS_PDATA (1 << 4) >> + >> /* Allocate driver private data on a DMA boundary */ >> -#define DM_FLAG_ALLOC_PRIV_DMA (1 << 4) >> +#define DM_FLAG_ALLOC_PRIV_DMA (1 << 5) >> >> /** >> * struct udevice - An instance of a driver >> @@ -54,6 +57,7 @@ struct driver_info; >> * @name: Name of device, typically the FDT node name >> * @platdata: Configuration data for this device >> * @parent_platdata: The parent bus's configuration data for this device >> + * @uclass_platdata: The uclass's configuration data for this device >> * @of_offset: Device tree node offset for this device (- for none) >> * @driver_data: Driver data word for the entry that matched this device with >> * its driver >> @@ -75,6 +79,7 @@ struct udevice { >> const char *name; >> void *platdata; >> void *parent_platdata; >> + void *uclass_platdata; >> int of_offset; >> ulong driver_data; >> struct udevice *parent; >> @@ -210,6 +215,16 @@ void *dev_get_platdata(struct udevice *dev); >> void *dev_get_parent_platdata(struct udevice *dev); >> >> /** >> + * dev_get_uclass_platdata() - Get the uclass platform data for a device >> + * >> + * This checks that dev is not NULL, but no other checks for now >> + * >> + * @dev Device to check >> + * @return uclass's platform data, or NULL if none >> + */ >> +void *dev_get_uclass_platdata(struct udevice *dev); >> + >> +/** >> * dev_get_parentdata() - Get the parent data for a device >> * >> * The parent data is data stored in the device but owned by the parent. >> diff --git a/include/dm/uclass.h b/include/dm/uclass.h >> index d57d804..b271472 100644 >> --- a/include/dm/uclass.h >> +++ b/include/dm/uclass.h >> @@ -65,6 +65,9 @@ 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_device_platdata_auto_alloc_size: Each device can hold platform data >> + * owned by the uclass as 'dev->uclass_platdata'. If the value is non-zero, >> + * then this will be automatically allocated. >> * @per_child_auto_alloc_size: Each child device (of a parent in this >> * uclass) can hold parent data for the device/uclass. This value is only >> * used as a falback if this member is 0 in the driver. >> @@ -90,6 +93,7 @@ struct uclass_driver { >> int (*destroy)(struct uclass *class); >> int priv_auto_alloc_size; >> int per_device_auto_alloc_size; >> + int per_device_platdata_auto_alloc_size; >> int per_child_auto_alloc_size; >> int per_child_platdata_auto_alloc_size; >> const void *ops; >> -- >> 1.9.1 >> > > Regards, > Simon > Thanks, -- Przemyslaw Marczak Samsung R&D Institute Poland Samsung Electronics p.marczak at samsung.com ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH 2/2] dm: test: Add tests for device's uclass platform data 2015-04-08 13:01 [U-Boot] [PATCH 0/2] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 2015-04-08 13:01 ` [U-Boot] [PATCH 1/2] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak @ 2015-04-08 13:01 ` Przemyslaw Marczak 2015-04-08 13:47 ` Simon Glass 2015-04-08 15:32 ` [U-Boot] [PATCH V2 0/3] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 2 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 13:01 UTC (permalink / raw) To: u-boot This test introduces new test structure type:dm_test_perdev_uc_pdata. The structure consists of three int values only. For the test purposes, three pattern values are defined by enum, starting with TEST_UC_PDATA_INTVAL1. This commit adds two test cases for uclass platform data: - Test: dm_test_autobind_uclass_pdata_alloc - this tests if: * uclass driver sets: .per_device_platdata_auto_alloc_size field * the devices's: dev->uclass_platdata is non-NULL - Test: dm_test_autobind_uclass_pdata_valid - this tests: * if the devices's: dev->uclass_platdata is non-NULL * the structure of type 'dm_test_perdev_uc_pdata' allocated at address pointed by dev->uclass_platdata. Each structure field, should be equal to proper pattern data, starting from .intval1 == TEST_UC_PDATA_INTVAL1. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- include/dm/test.h | 20 +++++++++++++++++++ test/dm/core.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/dm/test-uclass.c | 11 +++++++++++ 3 files changed, 86 insertions(+) diff --git a/include/dm/test.h b/include/dm/test.h index 9c4b8d3..f03fbcb 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -98,6 +98,26 @@ struct dm_test_parent_data { int flag; }; +/* Test values for test device's uclass platform data */ +enum { + TEST_UC_PDATA_INTVAL1 = 2, + TEST_UC_PDATA_INTVAL2 = 334, + TEST_UC_PDATA_INTVAL3 = 789452, +}; + +/** + * struct dm_test_uclass_platda - uclass's information on each device + * + * @intval1: set to TEST_UC_PDATA_INTVAL1 in .post_bind method of test uclass + * @intval2: set to TEST_UC_PDATA_INTVAL2 in .post_bind method of test uclass + * @intval3: set to TEST_UC_PDATA_INTVAL3 in .post_bind method of test uclass + */ +struct dm_test_perdev_uc_pdata { + int intval1; + int intval2; + int intval3; +}; + /* * Operation counts for the test driver, used to check that each method is * called correctly diff --git a/test/dm/core.c b/test/dm/core.c index 990d390..ce8a958 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -129,6 +129,61 @@ static int dm_test_autobind(struct dm_test_state *dms) } DM_TEST(dm_test_autobind, 0); +/* Test that binding with uclass platdata allocation occurs correctly */ +static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) +{ + struct dm_test_perdev_uc_pdata *uc_pdata; + struct udevice *dev; + struct uclass *uc; + int i; + + ut_assertok(uclass_get(UCLASS_TEST, &uc)); + ut_assert(uc); + + /** + * Test if test uclass driver requires allocation for the uclass + * platform data and then check the dev->uclass_platdata pointer. + */ + ut_assert(uc->uc_drv->per_device_platdata_auto_alloc_size); + + for (i = 0; i < 3; i++) { + ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev)); + ut_assert(dev); + + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + } + + return 0; +} +DM_TEST(dm_test_autobind_uclass_pdata_alloc, DM_TESTF_SCAN_PDATA); + +/* Test that binding with uclass platdata setting occurs correctly */ +static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) +{ + struct dm_test_perdev_uc_pdata *uc_pdata; + struct udevice *dev; + int i; + + /** + * In the test_postbind() method of test uclass driver, the uclass + * platform data should be set with three test int values - test it. + */ + for (i = 0; i < 3; i++) { + ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev)); + ut_assert(dev); + + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1); + ut_assert(uc_pdata->intval2 == TEST_UC_PDATA_INTVAL2); + ut_assert(uc_pdata->intval3 == TEST_UC_PDATA_INTVAL3); + } + + return 0; +} +DM_TEST(dm_test_autobind_uclass_pdata_valid, DM_TESTF_SCAN_PDATA); + /* Test that autoprobe finds all the expected devices */ static int dm_test_autoprobe(struct dm_test_state *dms) { diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c index 7cb37f7..4ae75ef 100644 --- a/test/dm/test-uclass.c +++ b/test/dm/test-uclass.c @@ -30,9 +30,18 @@ int test_ping(struct udevice *dev, int pingval, int *pingret) static int test_post_bind(struct udevice *dev) { + struct dm_test_perdev_uc_pdata *uc_pdata; + dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++; ut_assert(!device_active(dev)); + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + + uc_pdata->intval1 = TEST_UC_PDATA_INTVAL1; + uc_pdata->intval2 = TEST_UC_PDATA_INTVAL2; + uc_pdata->intval3 = TEST_UC_PDATA_INTVAL3; + return 0; } @@ -115,4 +124,6 @@ UCLASS_DRIVER(test) = { .destroy = test_destroy, .priv_auto_alloc_size = sizeof(struct dm_test_uclass_priv), .per_device_auto_alloc_size = sizeof(struct dm_test_uclass_perdev_priv), + .per_device_platdata_auto_alloc_size = + sizeof(struct dm_test_perdev_uc_pdata), }; -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH 2/2] dm: test: Add tests for device's uclass platform data 2015-04-08 13:01 ` [U-Boot] [PATCH 2/2] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak @ 2015-04-08 13:47 ` Simon Glass 2015-04-08 13:58 ` Przemyslaw Marczak 0 siblings, 1 reply; 61+ messages in thread From: Simon Glass @ 2015-04-08 13:47 UTC (permalink / raw) To: u-boot Hi Przemyslaw, On 8 April 2015 at 07:01, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This test introduces new test structure type:dm_test_perdev_uc_pdata. > The structure consists of three int values only. For the test purposes, > three pattern values are defined by enum, starting with TEST_UC_PDATA_INTVAL1. > > This commit adds two test cases for uclass platform data: > - Test: dm_test_autobind_uclass_pdata_alloc - this tests if: > * uclass driver sets: .per_device_platdata_auto_alloc_size field > * the devices's: dev->uclass_platdata is non-NULL > > - Test: dm_test_autobind_uclass_pdata_valid - this tests: > * if the devices's: dev->uclass_platdata is non-NULL > * the structure of type 'dm_test_perdev_uc_pdata' allocated at address > pointed by dev->uclass_platdata. Each structure field, should be equal > to proper pattern data, starting from .intval1 == TEST_UC_PDATA_INTVAL1. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > include/dm/test.h | 20 +++++++++++++++++++ > test/dm/core.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ > test/dm/test-uclass.c | 11 +++++++++++ > 3 files changed, 86 insertions(+) Acked-by: Simon Glass <sjg@chromium.org> (one nit below) > > diff --git a/include/dm/test.h b/include/dm/test.h > index 9c4b8d3..f03fbcb 100644 > --- a/include/dm/test.h > +++ b/include/dm/test.h > @@ -98,6 +98,26 @@ struct dm_test_parent_data { > int flag; > }; > > +/* Test values for test device's uclass platform data */ > +enum { > + TEST_UC_PDATA_INTVAL1 = 2, > + TEST_UC_PDATA_INTVAL2 = 334, > + TEST_UC_PDATA_INTVAL3 = 789452, > +}; > + > +/** > + * struct dm_test_uclass_platda - uclass's information on each device > + * > + * @intval1: set to TEST_UC_PDATA_INTVAL1 in .post_bind method of test uclass > + * @intval2: set to TEST_UC_PDATA_INTVAL2 in .post_bind method of test uclass > + * @intval3: set to TEST_UC_PDATA_INTVAL3 in .post_bind method of test uclass > + */ > +struct dm_test_perdev_uc_pdata { > + int intval1; > + int intval2; > + int intval3; > +}; > + > /* > * Operation counts for the test driver, used to check that each method is > * called correctly > diff --git a/test/dm/core.c b/test/dm/core.c > index 990d390..ce8a958 100644 > --- a/test/dm/core.c > +++ b/test/dm/core.c > @@ -129,6 +129,61 @@ static int dm_test_autobind(struct dm_test_state *dms) > } > DM_TEST(dm_test_autobind, 0); > > +/* Test that binding with uclass platdata allocation occurs correctly */ > +static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) > +{ > + struct dm_test_perdev_uc_pdata *uc_pdata; > + struct udevice *dev; > + struct uclass *uc; > + int i; > + > + ut_assertok(uclass_get(UCLASS_TEST, &uc)); > + ut_assert(uc); > + > + /** > + * Test if test uclass driver requires allocation for the uclass > + * platform data and then check the dev->uclass_platdata pointer. > + */ > + ut_assert(uc->uc_drv->per_device_platdata_auto_alloc_size); > + > + for (i = 0; i < 3; i++) { nit: Can you add an enum for the '3' here, and below? It could be TEST_UC_PDATA_COUNT if you like. > + ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev)); > + ut_assert(dev); > + > + uc_pdata = dev_get_uclass_platdata(dev); > + ut_assert(uc_pdata); > + } > + > + return 0; > +} > +DM_TEST(dm_test_autobind_uclass_pdata_alloc, DM_TESTF_SCAN_PDATA); > + > +/* Test that binding with uclass platdata setting occurs correctly */ > +static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) > +{ > + struct dm_test_perdev_uc_pdata *uc_pdata; > + struct udevice *dev; > + int i; > + > + /** > + * In the test_postbind() method of test uclass driver, the uclass > + * platform data should be set with three test int values - test it. > + */ > + for (i = 0; i < 3; i++) { > + ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev)); > + ut_assert(dev); > + > + uc_pdata = dev_get_uclass_platdata(dev); > + ut_assert(uc_pdata); > + ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1); > + ut_assert(uc_pdata->intval2 == TEST_UC_PDATA_INTVAL2); > + ut_assert(uc_pdata->intval3 == TEST_UC_PDATA_INTVAL3); > + } > + > + return 0; > +} > +DM_TEST(dm_test_autobind_uclass_pdata_valid, DM_TESTF_SCAN_PDATA); > + > /* Test that autoprobe finds all the expected devices */ > static int dm_test_autoprobe(struct dm_test_state *dms) > { > diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c > index 7cb37f7..4ae75ef 100644 > --- a/test/dm/test-uclass.c > +++ b/test/dm/test-uclass.c > @@ -30,9 +30,18 @@ int test_ping(struct udevice *dev, int pingval, int *pingret) > > static int test_post_bind(struct udevice *dev) > { > + struct dm_test_perdev_uc_pdata *uc_pdata; > + > dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++; > ut_assert(!device_active(dev)); > > + uc_pdata = dev_get_uclass_platdata(dev); > + ut_assert(uc_pdata); > + > + uc_pdata->intval1 = TEST_UC_PDATA_INTVAL1; > + uc_pdata->intval2 = TEST_UC_PDATA_INTVAL2; > + uc_pdata->intval3 = TEST_UC_PDATA_INTVAL3; > + > return 0; > } > > @@ -115,4 +124,6 @@ UCLASS_DRIVER(test) = { > .destroy = test_destroy, > .priv_auto_alloc_size = sizeof(struct dm_test_uclass_priv), > .per_device_auto_alloc_size = sizeof(struct dm_test_uclass_perdev_priv), > + .per_device_platdata_auto_alloc_size = > + sizeof(struct dm_test_perdev_uc_pdata), > }; > -- > 1.9.1 > Regards, Simon ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH 2/2] dm: test: Add tests for device's uclass platform data 2015-04-08 13:47 ` Simon Glass @ 2015-04-08 13:58 ` Przemyslaw Marczak 0 siblings, 0 replies; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 13:58 UTC (permalink / raw) To: u-boot Hello Simon, On 04/08/2015 03:47 PM, Simon Glass wrote: > Hi Przemyslaw, > > On 8 April 2015 at 07:01, Przemyslaw Marczak <p.marczak@samsung.com> wrote: >> This test introduces new test structure type:dm_test_perdev_uc_pdata. >> The structure consists of three int values only. For the test purposes, >> three pattern values are defined by enum, starting with TEST_UC_PDATA_INTVAL1. >> >> This commit adds two test cases for uclass platform data: >> - Test: dm_test_autobind_uclass_pdata_alloc - this tests if: >> * uclass driver sets: .per_device_platdata_auto_alloc_size field >> * the devices's: dev->uclass_platdata is non-NULL >> >> - Test: dm_test_autobind_uclass_pdata_valid - this tests: >> * if the devices's: dev->uclass_platdata is non-NULL >> * the structure of type 'dm_test_perdev_uc_pdata' allocated at address >> pointed by dev->uclass_platdata. Each structure field, should be equal >> to proper pattern data, starting from .intval1 == TEST_UC_PDATA_INTVAL1. >> >> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> >> Cc: Simon Glass <sjg@chromium.org> >> --- >> include/dm/test.h | 20 +++++++++++++++++++ >> test/dm/core.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ >> test/dm/test-uclass.c | 11 +++++++++++ >> 3 files changed, 86 insertions(+) > > Acked-by: Simon Glass <sjg@chromium.org> > > (one nit below) > >> >> diff --git a/include/dm/test.h b/include/dm/test.h >> index 9c4b8d3..f03fbcb 100644 >> --- a/include/dm/test.h >> +++ b/include/dm/test.h >> @@ -98,6 +98,26 @@ struct dm_test_parent_data { >> int flag; >> }; >> >> +/* Test values for test device's uclass platform data */ >> +enum { >> + TEST_UC_PDATA_INTVAL1 = 2, >> + TEST_UC_PDATA_INTVAL2 = 334, >> + TEST_UC_PDATA_INTVAL3 = 789452, >> +}; >> + >> +/** >> + * struct dm_test_uclass_platda - uclass's information on each device >> + * >> + * @intval1: set to TEST_UC_PDATA_INTVAL1 in .post_bind method of test uclass >> + * @intval2: set to TEST_UC_PDATA_INTVAL2 in .post_bind method of test uclass >> + * @intval3: set to TEST_UC_PDATA_INTVAL3 in .post_bind method of test uclass >> + */ >> +struct dm_test_perdev_uc_pdata { >> + int intval1; >> + int intval2; >> + int intval3; >> +}; >> + >> /* >> * Operation counts for the test driver, used to check that each method is >> * called correctly >> diff --git a/test/dm/core.c b/test/dm/core.c >> index 990d390..ce8a958 100644 >> --- a/test/dm/core.c >> +++ b/test/dm/core.c >> @@ -129,6 +129,61 @@ static int dm_test_autobind(struct dm_test_state *dms) >> } >> DM_TEST(dm_test_autobind, 0); >> >> +/* Test that binding with uclass platdata allocation occurs correctly */ >> +static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) >> +{ >> + struct dm_test_perdev_uc_pdata *uc_pdata; >> + struct udevice *dev; >> + struct uclass *uc; >> + int i; >> + >> + ut_assertok(uclass_get(UCLASS_TEST, &uc)); >> + ut_assert(uc); >> + >> + /** >> + * Test if test uclass driver requires allocation for the uclass >> + * platform data and then check the dev->uclass_platdata pointer. >> + */ >> + ut_assert(uc->uc_drv->per_device_platdata_auto_alloc_size); >> + >> + for (i = 0; i < 3; i++) { > > nit: Can you add an enum for the '3' here, and below? It could be > TEST_UC_PDATA_COUNT if you like. > Ok, I will add this. >> + ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev)); >> + ut_assert(dev); >> + >> + uc_pdata = dev_get_uclass_platdata(dev); >> + ut_assert(uc_pdata); >> + } >> + >> + return 0; >> +} >> +DM_TEST(dm_test_autobind_uclass_pdata_alloc, DM_TESTF_SCAN_PDATA); >> + >> +/* Test that binding with uclass platdata setting occurs correctly */ >> +static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) >> +{ >> + struct dm_test_perdev_uc_pdata *uc_pdata; >> + struct udevice *dev; >> + int i; >> + >> + /** >> + * In the test_postbind() method of test uclass driver, the uclass >> + * platform data should be set with three test int values - test it. >> + */ >> + for (i = 0; i < 3; i++) { >> + ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev)); >> + ut_assert(dev); >> + >> + uc_pdata = dev_get_uclass_platdata(dev); >> + ut_assert(uc_pdata); >> + ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1); >> + ut_assert(uc_pdata->intval2 == TEST_UC_PDATA_INTVAL2); >> + ut_assert(uc_pdata->intval3 == TEST_UC_PDATA_INTVAL3); >> + } >> + >> + return 0; >> +} >> +DM_TEST(dm_test_autobind_uclass_pdata_valid, DM_TESTF_SCAN_PDATA); >> + >> /* Test that autoprobe finds all the expected devices */ >> static int dm_test_autoprobe(struct dm_test_state *dms) >> { >> diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c >> index 7cb37f7..4ae75ef 100644 >> --- a/test/dm/test-uclass.c >> +++ b/test/dm/test-uclass.c >> @@ -30,9 +30,18 @@ int test_ping(struct udevice *dev, int pingval, int *pingret) >> >> static int test_post_bind(struct udevice *dev) >> { >> + struct dm_test_perdev_uc_pdata *uc_pdata; >> + >> dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++; >> ut_assert(!device_active(dev)); >> >> + uc_pdata = dev_get_uclass_platdata(dev); >> + ut_assert(uc_pdata); >> + >> + uc_pdata->intval1 = TEST_UC_PDATA_INTVAL1; >> + uc_pdata->intval2 = TEST_UC_PDATA_INTVAL2; >> + uc_pdata->intval3 = TEST_UC_PDATA_INTVAL3; >> + >> return 0; >> } >> >> @@ -115,4 +124,6 @@ UCLASS_DRIVER(test) = { >> .destroy = test_destroy, >> .priv_auto_alloc_size = sizeof(struct dm_test_uclass_priv), >> .per_device_auto_alloc_size = sizeof(struct dm_test_uclass_perdev_priv), >> + .per_device_platdata_auto_alloc_size = >> + sizeof(struct dm_test_perdev_uc_pdata), >> }; >> -- >> 1.9.1 >> > > Regards, > Simon > Thanks for a quick review. I will resend it in a moment Best regards, -- Przemyslaw Marczak Samsung R&D Institute Poland Samsung Electronics p.marczak at samsung.com ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V2 0/3] dm: core: add device's uclass platform data and tests 2015-04-08 13:01 [U-Boot] [PATCH 0/2] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 2015-04-08 13:01 ` [U-Boot] [PATCH 1/2] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak 2015-04-08 13:01 ` [U-Boot] [PATCH 2/2] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak @ 2015-04-08 15:32 ` Przemyslaw Marczak 2015-04-08 15:32 ` [U-Boot] [PATCH V2 1/3] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak ` (3 more replies) 2 siblings, 4 replies; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 15:32 UTC (permalink / raw) To: u-boot The struct udevice provides two fields for device's platform data: - .platdata - to keep platform-dependent data for the device driver - .parent_platdata - to keep platform-dependent data for the device parent Some implementations may need addidional platform data, which could be owned by the uclass. For example, the regulator device's constraints. This patchset adds the additional field: - .uclass_platdata - to keep platform-dependend data for the uclass driver Two tests are added to the test framework: - one for check dev->uclass_platdata pointer - second for validation the data assigned to by test uclass's post_bind() method Change in V2: - implementation of functions for getting the uclass's device without probe it - cleanup test code Przemyslaw Marczak (3): dm: core: add internal functions for getting the device without probe dm: core: Extend struct udevice by '.uclass_platdata' field. dm: test: Add tests for device's uclass platform data drivers/core/device-remove.c | 4 +++ drivers/core/device.c | 33 ++++++++++++++++++++++--- drivers/core/uclass.c | 59 +++++++++++++++++++++++++------------------- include/dm/device.h | 17 ++++++++++++- include/dm/test.h | 20 +++++++++++++++ include/dm/uclass-internal.h | 22 +++++++++++++++++ include/dm/uclass.h | 4 +++ test/dm/core.c | 55 +++++++++++++++++++++++++++++++++++++++++ test/dm/test-uclass.c | 11 +++++++++ 9 files changed, 195 insertions(+), 30 deletions(-) -- 1.9.1 ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V2 1/3] dm: core: add internal functions for getting the device without probe 2015-04-08 15:32 ` [U-Boot] [PATCH V2 0/3] dm: core: add device's uclass platform data and tests Przemyslaw Marczak @ 2015-04-08 15:32 ` Przemyslaw Marczak 2015-04-08 15:39 ` Simon Glass 2015-04-08 15:32 ` [U-Boot] [PATCH V2 2/3] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak ` (2 subsequent siblings) 3 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 15:32 UTC (permalink / raw) To: u-boot This commit extends the uclass-internal functions by: - uclass_find_first_device() - uclass_find_next_device() For both functions, the returned device is not probed. After some cleanup, the above functions are called by: - uclass_first_device() - uclass_next_device() for which, the returned device is probed. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V2: - new commit --- drivers/core/uclass.c | 59 +++++++++++++++++++++++++------------------- include/dm/uclass-internal.h | 22 +++++++++++++++++ 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 98c15e5..21ab0d5 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -156,6 +156,36 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp) return -ENODEV; } +int uclass_find_first_device(enum uclass_id id, struct udevice **devp) +{ + struct uclass *uc; + int ret; + + *devp = NULL; + ret = uclass_get(id, &uc); + if (ret) + return ret; + if (list_empty(&uc->dev_head)) + return 0; + + *devp = list_first_entry(&uc->dev_head, struct udevice, uclass_node); + + return 0; +} + +int uclass_find_next_device(struct udevice **devp) +{ + struct udevice *dev = *devp; + + *devp = NULL; + if (list_is_last(&dev->uclass_node, &dev->uclass->dev_head)) + return 0; + + *devp = list_entry(dev->uclass_node.next, struct udevice, uclass_node); + + return 0; +} + int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, bool find_req_seq, struct udevice **devp) { @@ -274,24 +304,12 @@ int uclass_get_device_by_of_offset(enum uclass_id id, int node, int uclass_first_device(enum uclass_id id, struct udevice **devp) { - struct uclass *uc; struct udevice *dev; int ret; *devp = NULL; - ret = uclass_get(id, &uc); - if (ret) - return ret; - if (list_empty(&uc->dev_head)) - return 0; - - dev = list_first_entry(&uc->dev_head, struct udevice, uclass_node); - ret = device_probe(dev); - if (ret) - return ret; - *devp = dev; - - return 0; + ret = uclass_find_first_device(id, &dev); + return uclass_get_device_tail(dev, ret, devp); } int uclass_next_device(struct udevice **devp) @@ -300,17 +318,8 @@ int uclass_next_device(struct udevice **devp) int ret; *devp = NULL; - if (list_is_last(&dev->uclass_node, &dev->uclass->dev_head)) - return 0; - - dev = list_entry(dev->uclass_node.next, struct udevice, - uclass_node); - ret = device_probe(dev); - if (ret) - return ret; - *devp = dev; - - return 0; + ret = uclass_find_next_device(&dev); + return uclass_get_device_tail(dev, ret, devp); } int uclass_bind_device(struct udevice *dev) diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index ae2a93d..befbae5 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -24,6 +24,28 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp); /** + * uclass_find_first_device() - Return the first device in a uclass + * @id: Id number of the uclass + * #devp: Returns pointer to device, or NULL on error + * + * The device is not prepared for use - this is an internal function + * + * @return 0 if OK (found or not found), -1 on error + */ +int uclass_find_first_device(enum uclass_id id, struct udevice **devp); + +/** + * uclass_find_next_device() - Return the next device in a uclass + * @devp: On entry, pointer to device to lookup. On exit, returns pointer + * to the next device in the same uclass, or NULL if none + * + * The device is not prepared for use - this is an internal function + * + * @return 0 if OK (found or not found), -1 on error + */ +int uclass_find_next_device(struct udevice **devp); + +/** * uclass_bind_device() - Associate device with a uclass * * Connect the device into uclass's list of devices. -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V2 1/3] dm: core: add internal functions for getting the device without probe 2015-04-08 15:32 ` [U-Boot] [PATCH V2 1/3] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak @ 2015-04-08 15:39 ` Simon Glass 2015-04-08 15:47 ` Przemyslaw Marczak 0 siblings, 1 reply; 61+ messages in thread From: Simon Glass @ 2015-04-08 15:39 UTC (permalink / raw) To: u-boot Hi Przemyslaw, On 8 April 2015 at 09:32, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit extends the uclass-internal functions by: > - uclass_find_first_device() > - uclass_find_next_device() > For both functions, the returned device is not probed. > > After some cleanup, the above functions are called by: > - uclass_first_device() > - uclass_next_device() > for which, the returned device is probed. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > Changes V2: > - new commit > --- > drivers/core/uclass.c | 59 +++++++++++++++++++++++++------------------- > include/dm/uclass-internal.h | 22 +++++++++++++++++ > 2 files changed, 56 insertions(+), 25 deletions(-) > Looks good, can you add a test? Regards, Simon ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V2 1/3] dm: core: add internal functions for getting the device without probe 2015-04-08 15:39 ` Simon Glass @ 2015-04-08 15:47 ` Przemyslaw Marczak 0 siblings, 0 replies; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 15:47 UTC (permalink / raw) To: u-boot Hello Simon, On 04/08/2015 05:39 PM, Simon Glass wrote: > Hi Przemyslaw, > > On 8 April 2015 at 09:32, Przemyslaw Marczak <p.marczak@samsung.com> wrote: >> This commit extends the uclass-internal functions by: >> - uclass_find_first_device() >> - uclass_find_next_device() >> For both functions, the returned device is not probed. >> >> After some cleanup, the above functions are called by: >> - uclass_first_device() >> - uclass_next_device() >> for which, the returned device is probed. >> >> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> >> Cc: Simon Glass <sjg@chromium.org> >> --- >> Changes V2: >> - new commit >> --- >> drivers/core/uclass.c | 59 +++++++++++++++++++++++++------------------- >> include/dm/uclass-internal.h | 22 +++++++++++++++++ >> 2 files changed, 56 insertions(+), 25 deletions(-) >> > > Looks good, can you add a test? > > Regards, > Simon > Ok, will add some simply test. Best regards, -- Przemyslaw Marczak Samsung R&D Institute Poland Samsung Electronics p.marczak at samsung.com ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V2 2/3] dm: core: Extend struct udevice by '.uclass_platdata' field. 2015-04-08 15:32 ` [U-Boot] [PATCH V2 0/3] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 2015-04-08 15:32 ` [U-Boot] [PATCH V2 1/3] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak @ 2015-04-08 15:32 ` Przemyslaw Marczak 2015-04-08 15:32 ` [U-Boot] [PATCH V2 3/3] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak 2015-04-08 17:06 ` [U-Boot] [PATCH V3 0/4] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 3 siblings, 0 replies; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 15:32 UTC (permalink / raw) To: u-boot This commit adds 'uclass_platdata' field to 'struct udevice', which can be automatically allocated at bind. The allocation size is defined in 'struct uclass_driver' as 'per_device_platdata_auto_alloc_size'. New device's flag is added: DM_FLAG_ALLOC_UCLASS_PDATA, which is used for memory freeing at device unbind method. As for other udevice's fields, a complementary function is added: - dev_get_uclass_platdata() Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V2: - none --- drivers/core/device-remove.c | 4 ++++ drivers/core/device.c | 33 +++++++++++++++++++++++++++++---- include/dm/device.h | 17 ++++++++++++++++- include/dm/uclass.h | 4 ++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 7fee1c0..6a16b4f 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -92,6 +92,10 @@ int device_unbind(struct udevice *dev) free(dev->platdata); dev->platdata = NULL; } + if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { + free(dev->uclass_platdata); + dev->uclass_platdata = NULL; + } if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { free(dev->parent_platdata); dev->parent_platdata = NULL; diff --git a/drivers/core/device.c b/drivers/core/device.c index ccaa99c..80eb55b 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -30,7 +30,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, { struct udevice *dev; struct uclass *uc; - int ret = 0; + int size, ret = 0; *devp = NULL; if (!name) @@ -79,9 +79,19 @@ int device_bind(struct udevice *parent, const struct driver *drv, goto fail_alloc1; } } - if (parent) { - int size = parent->driver->per_child_platdata_auto_alloc_size; + size = uc->uc_drv->per_device_platdata_auto_alloc_size; + if (size) { + dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA; + dev->uclass_platdata = calloc(1, size); + if (!dev->uclass_platdata) { + ret = -ENOMEM; + goto fail_alloc2; + } + } + + if (parent) { + size = parent->driver->per_child_platdata_auto_alloc_size; if (!size) { size = parent->uclass->uc_drv-> per_child_platdata_auto_alloc_size; @@ -91,7 +101,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, dev->parent_platdata = calloc(1, size); if (!dev->parent_platdata) { ret = -ENOMEM; - goto fail_alloc2; + goto fail_alloc3; } } } @@ -139,6 +149,11 @@ fail_uclass_bind: free(dev->parent_platdata); dev->parent_platdata = NULL; } +fail_alloc3: + if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { + free(dev->uclass_platdata); + dev->uclass_platdata = NULL; + } fail_alloc2: if (dev->flags & DM_FLAG_ALLOC_PDATA) { free(dev->platdata); @@ -314,6 +329,16 @@ void *dev_get_parent_platdata(struct udevice *dev) return dev->parent_platdata; } +void *dev_get_uclass_platdata(struct udevice *dev) +{ + if (!dev) { + dm_warn("%s: null device", __func__); + return NULL; + } + + return dev->uclass_platdata; +} + void *dev_get_priv(struct udevice *dev) { if (!dev) { diff --git a/include/dm/device.h b/include/dm/device.h index c11342c..ad002fe 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -30,8 +30,11 @@ struct driver_info; /* DM is responsible for allocating and freeing parent_platdata */ #define DM_FLAG_ALLOC_PARENT_PDATA (1 << 3) +/* DM is responsible for allocating and freeing uclass_platdata */ +#define DM_FLAG_ALLOC_UCLASS_PDATA (1 << 4) + /* Allocate driver private data on a DMA boundary */ -#define DM_FLAG_ALLOC_PRIV_DMA (1 << 4) +#define DM_FLAG_ALLOC_PRIV_DMA (1 << 5) /** * struct udevice - An instance of a driver @@ -54,6 +57,7 @@ struct driver_info; * @name: Name of device, typically the FDT node name * @platdata: Configuration data for this device * @parent_platdata: The parent bus's configuration data for this device + * @uclass_platdata: The uclass's configuration data for this device * @of_offset: Device tree node offset for this device (- for none) * @driver_data: Driver data word for the entry that matched this device with * its driver @@ -75,6 +79,7 @@ struct udevice { const char *name; void *platdata; void *parent_platdata; + void *uclass_platdata; int of_offset; ulong driver_data; struct udevice *parent; @@ -210,6 +215,16 @@ void *dev_get_platdata(struct udevice *dev); void *dev_get_parent_platdata(struct udevice *dev); /** + * dev_get_uclass_platdata() - Get the uclass platform data for a device + * + * This checks that dev is not NULL, but no other checks for now + * + * @dev Device to check + * @return uclass's platform data, or NULL if none + */ +void *dev_get_uclass_platdata(struct udevice *dev); + +/** * dev_get_parentdata() - Get the parent data for a device * * The parent data is data stored in the device but owned by the parent. diff --git a/include/dm/uclass.h b/include/dm/uclass.h index d57d804..b271472 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -65,6 +65,9 @@ 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_device_platdata_auto_alloc_size: Each device can hold platform data + * owned by the uclass as 'dev->uclass_platdata'. If the value is non-zero, + * then this will be automatically allocated. * @per_child_auto_alloc_size: Each child device (of a parent in this * uclass) can hold parent data for the device/uclass. This value is only * used as a falback if this member is 0 in the driver. @@ -90,6 +93,7 @@ struct uclass_driver { int (*destroy)(struct uclass *class); int priv_auto_alloc_size; int per_device_auto_alloc_size; + int per_device_platdata_auto_alloc_size; int per_child_auto_alloc_size; int per_child_platdata_auto_alloc_size; const void *ops; -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V2 3/3] dm: test: Add tests for device's uclass platform data 2015-04-08 15:32 ` [U-Boot] [PATCH V2 0/3] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 2015-04-08 15:32 ` [U-Boot] [PATCH V2 1/3] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak 2015-04-08 15:32 ` [U-Boot] [PATCH V2 2/3] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak @ 2015-04-08 15:32 ` Przemyslaw Marczak 2015-04-08 17:06 ` [U-Boot] [PATCH V3 0/4] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 3 siblings, 0 replies; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 15:32 UTC (permalink / raw) To: u-boot This test introduces new test structure type:dm_test_perdev_uc_pdata. The structure consists of three int values only. For the test purposes, three pattern values are defined by enum, starting with TEST_UC_PDATA_INTVAL1. This commit adds two test cases for uclass platform data: - Test: dm_test_autobind_uclass_pdata_alloc - this tests if: * uclass driver sets: .per_device_platdata_auto_alloc_size field * the devices's: dev->uclass_platdata is non-NULL - Test: dm_test_autobind_uclass_pdata_valid - this tests: * if the devices's: dev->uclass_platdata is non-NULL * the structure of type 'dm_test_perdev_uc_pdata' allocated at address pointed by dev->uclass_platdata. Each structure field, should be equal to proper pattern data, starting from .intval1 == TEST_UC_PDATA_INTVAL1. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V2: - update test functions with calls: uclass_find_first/next_device() --- include/dm/test.h | 20 +++++++++++++++++++ test/dm/core.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/dm/test-uclass.c | 11 +++++++++++ 3 files changed, 86 insertions(+) diff --git a/include/dm/test.h b/include/dm/test.h index 9c4b8d3..f03fbcb 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -98,6 +98,26 @@ struct dm_test_parent_data { int flag; }; +/* Test values for test device's uclass platform data */ +enum { + TEST_UC_PDATA_INTVAL1 = 2, + TEST_UC_PDATA_INTVAL2 = 334, + TEST_UC_PDATA_INTVAL3 = 789452, +}; + +/** + * struct dm_test_uclass_platda - uclass's information on each device + * + * @intval1: set to TEST_UC_PDATA_INTVAL1 in .post_bind method of test uclass + * @intval2: set to TEST_UC_PDATA_INTVAL2 in .post_bind method of test uclass + * @intval3: set to TEST_UC_PDATA_INTVAL3 in .post_bind method of test uclass + */ +struct dm_test_perdev_uc_pdata { + int intval1; + int intval2; + int intval3; +}; + /* * Operation counts for the test driver, used to check that each method is * called correctly diff --git a/test/dm/core.c b/test/dm/core.c index 990d390..009ad36 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -129,6 +129,61 @@ static int dm_test_autobind(struct dm_test_state *dms) } DM_TEST(dm_test_autobind, 0); +/* Test that binding with uclass platdata allocation occurs correctly */ +static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) +{ + struct dm_test_perdev_uc_pdata *uc_pdata; + struct udevice *dev; + struct uclass *uc; + + ut_assertok(uclass_get(UCLASS_TEST, &uc)); + ut_assert(uc); + + /** + * Test if test uclass driver requires allocation for the uclass + * platform data and then check the dev->uclass_platdata pointer. + */ + ut_assert(uc->uc_drv->per_device_platdata_auto_alloc_size); + + for (uclass_find_first_device(UCLASS_TEST, &dev); + dev; + uclass_find_next_device(&dev)) { + ut_assert(dev); + + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + } + + return 0; +} +DM_TEST(dm_test_autobind_uclass_pdata_alloc, DM_TESTF_SCAN_PDATA); + +/* Test that binding with uclass platdata setting occurs correctly */ +static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) +{ + struct dm_test_perdev_uc_pdata *uc_pdata; + struct udevice *dev; + + /** + * In the test_postbind() method of test uclass driver, the uclass + * platform data should be set to three test int values - test it. + */ + for (uclass_find_first_device(UCLASS_TEST, &dev); + dev; + uclass_find_next_device(&dev)) { + ut_assert(dev); + + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1); + ut_assert(uc_pdata->intval2 == TEST_UC_PDATA_INTVAL2); + ut_assert(uc_pdata->intval3 == TEST_UC_PDATA_INTVAL3); + } + + return 0; +} +DM_TEST(dm_test_autobind_uclass_pdata_valid, DM_TESTF_SCAN_PDATA); + /* Test that autoprobe finds all the expected devices */ static int dm_test_autoprobe(struct dm_test_state *dms) { diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c index 7cb37f7..4ae75ef 100644 --- a/test/dm/test-uclass.c +++ b/test/dm/test-uclass.c @@ -30,9 +30,18 @@ int test_ping(struct udevice *dev, int pingval, int *pingret) static int test_post_bind(struct udevice *dev) { + struct dm_test_perdev_uc_pdata *uc_pdata; + dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++; ut_assert(!device_active(dev)); + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + + uc_pdata->intval1 = TEST_UC_PDATA_INTVAL1; + uc_pdata->intval2 = TEST_UC_PDATA_INTVAL2; + uc_pdata->intval3 = TEST_UC_PDATA_INTVAL3; + return 0; } @@ -115,4 +124,6 @@ UCLASS_DRIVER(test) = { .destroy = test_destroy, .priv_auto_alloc_size = sizeof(struct dm_test_uclass_priv), .per_device_auto_alloc_size = sizeof(struct dm_test_uclass_perdev_priv), + .per_device_platdata_auto_alloc_size = + sizeof(struct dm_test_perdev_uc_pdata), }; -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V3 0/4] dm: core: add device's uclass platform data and tests 2015-04-08 15:32 ` [U-Boot] [PATCH V2 0/3] dm: core: add device's uclass platform data and tests Przemyslaw Marczak ` (2 preceding siblings ...) 2015-04-08 15:32 ` [U-Boot] [PATCH V2 3/3] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak @ 2015-04-08 17:06 ` Przemyslaw Marczak 2015-04-08 17:06 ` [U-Boot] [PATCH V3 1/4] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak ` (5 more replies) 3 siblings, 6 replies; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 17:06 UTC (permalink / raw) To: u-boot The struct udevice provides two fields for device's platform data: - .platdata - to keep platform-dependent data for the device driver - .parent_platdata - to keep platform-dependent data for the device parent Some implementations may need addidional platform data, which could be owned by the uclass. For example, the regulator device's constraints. This patchset adds the additional field: - .uclass_platdata - to keep platform-dependend data for the uclass driver Two tests are added to the test framework: - one for check dev->uclass_platdata pointer - second for validation the data assigned to by test uclass's post_bind() method Change in V2: - implementation of functions for getting the uclass's device without probe it - cleanup test code Change in V3: - add tests for uclass device get/find functions Przemyslaw Marczak (4): dm: core: add internal functions for getting the device without probe dm: core: Extend struct udevice by '.uclass_platdata' field. dm: test: Add tests for device's uclass platform data dm: test: Add tests for get/find uclass devices drivers/core/device-remove.c | 4 ++ drivers/core/device.c | 33 ++++++++++++++-- drivers/core/uclass.c | 59 ++++++++++++++++------------- include/dm/device.h | 17 ++++++++- include/dm/test.h | 20 ++++++++++ include/dm/uclass-internal.h | 22 +++++++++++ include/dm/uclass.h | 4 ++ test/dm/core.c | 89 +++++++++++++++++++++++++++++++++++++++++++- test/dm/test-uclass.c | 11 ++++++ 9 files changed, 228 insertions(+), 31 deletions(-) -- 1.9.1 ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V3 1/4] dm: core: add internal functions for getting the device without probe 2015-04-08 17:06 ` [U-Boot] [PATCH V3 0/4] dm: core: add device's uclass platform data and tests Przemyslaw Marczak @ 2015-04-08 17:06 ` Przemyslaw Marczak 2015-04-09 1:47 ` Simon Glass 2015-04-08 17:06 ` [U-Boot] [PATCH V3 2/4] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak ` (4 subsequent siblings) 5 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 17:06 UTC (permalink / raw) To: u-boot This commit extends the uclass-internal functions by: - uclass_find_first_device() - uclass_find_next_device() For both functions, the returned device is not probed. After some cleanup, the above functions are called by: - uclass_first_device() - uclass_next_device() for which, the returned device is probed. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V2: - new commit Changes V3: - none --- drivers/core/uclass.c | 59 +++++++++++++++++++++++++------------------- include/dm/uclass-internal.h | 22 +++++++++++++++++ 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 98c15e5..21ab0d5 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -156,6 +156,36 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp) return -ENODEV; } +int uclass_find_first_device(enum uclass_id id, struct udevice **devp) +{ + struct uclass *uc; + int ret; + + *devp = NULL; + ret = uclass_get(id, &uc); + if (ret) + return ret; + if (list_empty(&uc->dev_head)) + return 0; + + *devp = list_first_entry(&uc->dev_head, struct udevice, uclass_node); + + return 0; +} + +int uclass_find_next_device(struct udevice **devp) +{ + struct udevice *dev = *devp; + + *devp = NULL; + if (list_is_last(&dev->uclass_node, &dev->uclass->dev_head)) + return 0; + + *devp = list_entry(dev->uclass_node.next, struct udevice, uclass_node); + + return 0; +} + int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, bool find_req_seq, struct udevice **devp) { @@ -274,24 +304,12 @@ int uclass_get_device_by_of_offset(enum uclass_id id, int node, int uclass_first_device(enum uclass_id id, struct udevice **devp) { - struct uclass *uc; struct udevice *dev; int ret; *devp = NULL; - ret = uclass_get(id, &uc); - if (ret) - return ret; - if (list_empty(&uc->dev_head)) - return 0; - - dev = list_first_entry(&uc->dev_head, struct udevice, uclass_node); - ret = device_probe(dev); - if (ret) - return ret; - *devp = dev; - - return 0; + ret = uclass_find_first_device(id, &dev); + return uclass_get_device_tail(dev, ret, devp); } int uclass_next_device(struct udevice **devp) @@ -300,17 +318,8 @@ int uclass_next_device(struct udevice **devp) int ret; *devp = NULL; - if (list_is_last(&dev->uclass_node, &dev->uclass->dev_head)) - return 0; - - dev = list_entry(dev->uclass_node.next, struct udevice, - uclass_node); - ret = device_probe(dev); - if (ret) - return ret; - *devp = dev; - - return 0; + ret = uclass_find_next_device(&dev); + return uclass_get_device_tail(dev, ret, devp); } int uclass_bind_device(struct udevice *dev) diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index ae2a93d..befbae5 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -24,6 +24,28 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp); /** + * uclass_find_first_device() - Return the first device in a uclass + * @id: Id number of the uclass + * #devp: Returns pointer to device, or NULL on error + * + * The device is not prepared for use - this is an internal function + * + * @return 0 if OK (found or not found), -1 on error + */ +int uclass_find_first_device(enum uclass_id id, struct udevice **devp); + +/** + * uclass_find_next_device() - Return the next device in a uclass + * @devp: On entry, pointer to device to lookup. On exit, returns pointer + * to the next device in the same uclass, or NULL if none + * + * The device is not prepared for use - this is an internal function + * + * @return 0 if OK (found or not found), -1 on error + */ +int uclass_find_next_device(struct udevice **devp); + +/** * uclass_bind_device() - Associate device with a uclass * * Connect the device into uclass's list of devices. -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V3 1/4] dm: core: add internal functions for getting the device without probe 2015-04-08 17:06 ` [U-Boot] [PATCH V3 1/4] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak @ 2015-04-09 1:47 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-09 1:47 UTC (permalink / raw) To: u-boot On 8 April 2015 at 11:06, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit extends the uclass-internal functions by: > - uclass_find_first_device() > - uclass_find_next_device() > For both functions, the returned device is not probed. > > After some cleanup, the above functions are called by: > - uclass_first_device() > - uclass_next_device() > for which, the returned device is probed. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > Changes V2: > - new commit > > Changes V3: > - none > --- > drivers/core/uclass.c | 59 +++++++++++++++++++++++++------------------- > include/dm/uclass-internal.h | 22 +++++++++++++++++ > 2 files changed, 56 insertions(+), 25 deletions(-) Acked-by: Simon Glass <sjg@chromium.org> ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V3 2/4] dm: core: Extend struct udevice by '.uclass_platdata' field. 2015-04-08 17:06 ` [U-Boot] [PATCH V3 0/4] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 2015-04-08 17:06 ` [U-Boot] [PATCH V3 1/4] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak @ 2015-04-08 17:06 ` Przemyslaw Marczak 2015-04-09 1:47 ` Simon Glass 2015-04-08 17:06 ` [U-Boot] [PATCH V3 3/4] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak ` (3 subsequent siblings) 5 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 17:06 UTC (permalink / raw) To: u-boot This commit adds 'uclass_platdata' field to 'struct udevice', which can be automatically allocated at bind. The allocation size is defined in 'struct uclass_driver' as 'per_device_platdata_auto_alloc_size'. New device's flag is added: DM_FLAG_ALLOC_UCLASS_PDATA, which is used for memory freeing at device unbind method. As for other udevice's fields, a complementary function is added: - dev_get_uclass_platdata() Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V2: - none Changes V3: - none --- drivers/core/device-remove.c | 4 ++++ drivers/core/device.c | 33 +++++++++++++++++++++++++++++---- include/dm/device.h | 17 ++++++++++++++++- include/dm/uclass.h | 4 ++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 7fee1c0..6a16b4f 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -92,6 +92,10 @@ int device_unbind(struct udevice *dev) free(dev->platdata); dev->platdata = NULL; } + if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { + free(dev->uclass_platdata); + dev->uclass_platdata = NULL; + } if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { free(dev->parent_platdata); dev->parent_platdata = NULL; diff --git a/drivers/core/device.c b/drivers/core/device.c index ccaa99c..80eb55b 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -30,7 +30,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, { struct udevice *dev; struct uclass *uc; - int ret = 0; + int size, ret = 0; *devp = NULL; if (!name) @@ -79,9 +79,19 @@ int device_bind(struct udevice *parent, const struct driver *drv, goto fail_alloc1; } } - if (parent) { - int size = parent->driver->per_child_platdata_auto_alloc_size; + size = uc->uc_drv->per_device_platdata_auto_alloc_size; + if (size) { + dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA; + dev->uclass_platdata = calloc(1, size); + if (!dev->uclass_platdata) { + ret = -ENOMEM; + goto fail_alloc2; + } + } + + if (parent) { + size = parent->driver->per_child_platdata_auto_alloc_size; if (!size) { size = parent->uclass->uc_drv-> per_child_platdata_auto_alloc_size; @@ -91,7 +101,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, dev->parent_platdata = calloc(1, size); if (!dev->parent_platdata) { ret = -ENOMEM; - goto fail_alloc2; + goto fail_alloc3; } } } @@ -139,6 +149,11 @@ fail_uclass_bind: free(dev->parent_platdata); dev->parent_platdata = NULL; } +fail_alloc3: + if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { + free(dev->uclass_platdata); + dev->uclass_platdata = NULL; + } fail_alloc2: if (dev->flags & DM_FLAG_ALLOC_PDATA) { free(dev->platdata); @@ -314,6 +329,16 @@ void *dev_get_parent_platdata(struct udevice *dev) return dev->parent_platdata; } +void *dev_get_uclass_platdata(struct udevice *dev) +{ + if (!dev) { + dm_warn("%s: null device", __func__); + return NULL; + } + + return dev->uclass_platdata; +} + void *dev_get_priv(struct udevice *dev) { if (!dev) { diff --git a/include/dm/device.h b/include/dm/device.h index c11342c..ad002fe 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -30,8 +30,11 @@ struct driver_info; /* DM is responsible for allocating and freeing parent_platdata */ #define DM_FLAG_ALLOC_PARENT_PDATA (1 << 3) +/* DM is responsible for allocating and freeing uclass_platdata */ +#define DM_FLAG_ALLOC_UCLASS_PDATA (1 << 4) + /* Allocate driver private data on a DMA boundary */ -#define DM_FLAG_ALLOC_PRIV_DMA (1 << 4) +#define DM_FLAG_ALLOC_PRIV_DMA (1 << 5) /** * struct udevice - An instance of a driver @@ -54,6 +57,7 @@ struct driver_info; * @name: Name of device, typically the FDT node name * @platdata: Configuration data for this device * @parent_platdata: The parent bus's configuration data for this device + * @uclass_platdata: The uclass's configuration data for this device * @of_offset: Device tree node offset for this device (- for none) * @driver_data: Driver data word for the entry that matched this device with * its driver @@ -75,6 +79,7 @@ struct udevice { const char *name; void *platdata; void *parent_platdata; + void *uclass_platdata; int of_offset; ulong driver_data; struct udevice *parent; @@ -210,6 +215,16 @@ void *dev_get_platdata(struct udevice *dev); void *dev_get_parent_platdata(struct udevice *dev); /** + * dev_get_uclass_platdata() - Get the uclass platform data for a device + * + * This checks that dev is not NULL, but no other checks for now + * + * @dev Device to check + * @return uclass's platform data, or NULL if none + */ +void *dev_get_uclass_platdata(struct udevice *dev); + +/** * dev_get_parentdata() - Get the parent data for a device * * The parent data is data stored in the device but owned by the parent. diff --git a/include/dm/uclass.h b/include/dm/uclass.h index d57d804..b271472 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -65,6 +65,9 @@ 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_device_platdata_auto_alloc_size: Each device can hold platform data + * owned by the uclass as 'dev->uclass_platdata'. If the value is non-zero, + * then this will be automatically allocated. * @per_child_auto_alloc_size: Each child device (of a parent in this * uclass) can hold parent data for the device/uclass. This value is only * used as a falback if this member is 0 in the driver. @@ -90,6 +93,7 @@ struct uclass_driver { int (*destroy)(struct uclass *class); int priv_auto_alloc_size; int per_device_auto_alloc_size; + int per_device_platdata_auto_alloc_size; int per_child_auto_alloc_size; int per_child_platdata_auto_alloc_size; const void *ops; -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V3 2/4] dm: core: Extend struct udevice by '.uclass_platdata' field. 2015-04-08 17:06 ` [U-Boot] [PATCH V3 2/4] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak @ 2015-04-09 1:47 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-09 1:47 UTC (permalink / raw) To: u-boot On 8 April 2015 at 11:06, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit adds 'uclass_platdata' field to 'struct udevice', which > can be automatically allocated at bind. The allocation size is defined > in 'struct uclass_driver' as 'per_device_platdata_auto_alloc_size'. > > New device's flag is added: DM_FLAG_ALLOC_UCLASS_PDATA, which is used > for memory freeing at device unbind method. > > As for other udevice's fields, a complementary function is added: > - dev_get_uclass_platdata() > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > Changes V2: > - none > > Changes V3: > - none > --- > drivers/core/device-remove.c | 4 ++++ > drivers/core/device.c | 33 +++++++++++++++++++++++++++++---- > include/dm/device.h | 17 ++++++++++++++++- > include/dm/uclass.h | 4 ++++ > 4 files changed, 53 insertions(+), 5 deletions(-) Acked-by: Simon Glass <sjg@chromium.org> ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V3 3/4] dm: test: Add tests for device's uclass platform data 2015-04-08 17:06 ` [U-Boot] [PATCH V3 0/4] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 2015-04-08 17:06 ` [U-Boot] [PATCH V3 1/4] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak 2015-04-08 17:06 ` [U-Boot] [PATCH V3 2/4] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak @ 2015-04-08 17:06 ` Przemyslaw Marczak 2015-04-09 1:47 ` Simon Glass 2015-04-08 17:06 ` [U-Boot] [PATCH V3 4/4] dm: test: Add tests for get/find uclass devices Przemyslaw Marczak ` (2 subsequent siblings) 5 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 17:06 UTC (permalink / raw) To: u-boot This test introduces new test structure type:dm_test_perdev_uc_pdata. The structure consists of three int values only. For the test purposes, three pattern values are defined by enum, starting with TEST_UC_PDATA_INTVAL1. This commit adds two test cases for uclass platform data: - Test: dm_test_autobind_uclass_pdata_alloc - this tests if: * uclass driver sets: .per_device_platdata_auto_alloc_size field * the devices's: dev->uclass_platdata is non-NULL - Test: dm_test_autobind_uclass_pdata_valid - this tests: * if the devices's: dev->uclass_platdata is non-NULL * the structure of type 'dm_test_perdev_uc_pdata' allocated at address pointed by dev->uclass_platdata. Each structure field, should be equal to proper pattern data, starting from .intval1 == TEST_UC_PDATA_INTVAL1. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V2: - update test functions with calls: uclass_find_first/next_device() Changes V3: - none --- include/dm/test.h | 20 +++++++++++++++++++ test/dm/core.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/dm/test-uclass.c | 11 +++++++++++ 3 files changed, 86 insertions(+) diff --git a/include/dm/test.h b/include/dm/test.h index 9c4b8d3..f03fbcb 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -98,6 +98,26 @@ struct dm_test_parent_data { int flag; }; +/* Test values for test device's uclass platform data */ +enum { + TEST_UC_PDATA_INTVAL1 = 2, + TEST_UC_PDATA_INTVAL2 = 334, + TEST_UC_PDATA_INTVAL3 = 789452, +}; + +/** + * struct dm_test_uclass_platda - uclass's information on each device + * + * @intval1: set to TEST_UC_PDATA_INTVAL1 in .post_bind method of test uclass + * @intval2: set to TEST_UC_PDATA_INTVAL2 in .post_bind method of test uclass + * @intval3: set to TEST_UC_PDATA_INTVAL3 in .post_bind method of test uclass + */ +struct dm_test_perdev_uc_pdata { + int intval1; + int intval2; + int intval3; +}; + /* * Operation counts for the test driver, used to check that each method is * called correctly diff --git a/test/dm/core.c b/test/dm/core.c index 990d390..009ad36 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -129,6 +129,61 @@ static int dm_test_autobind(struct dm_test_state *dms) } DM_TEST(dm_test_autobind, 0); +/* Test that binding with uclass platdata allocation occurs correctly */ +static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) +{ + struct dm_test_perdev_uc_pdata *uc_pdata; + struct udevice *dev; + struct uclass *uc; + + ut_assertok(uclass_get(UCLASS_TEST, &uc)); + ut_assert(uc); + + /** + * Test if test uclass driver requires allocation for the uclass + * platform data and then check the dev->uclass_platdata pointer. + */ + ut_assert(uc->uc_drv->per_device_platdata_auto_alloc_size); + + for (uclass_find_first_device(UCLASS_TEST, &dev); + dev; + uclass_find_next_device(&dev)) { + ut_assert(dev); + + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + } + + return 0; +} +DM_TEST(dm_test_autobind_uclass_pdata_alloc, DM_TESTF_SCAN_PDATA); + +/* Test that binding with uclass platdata setting occurs correctly */ +static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) +{ + struct dm_test_perdev_uc_pdata *uc_pdata; + struct udevice *dev; + + /** + * In the test_postbind() method of test uclass driver, the uclass + * platform data should be set to three test int values - test it. + */ + for (uclass_find_first_device(UCLASS_TEST, &dev); + dev; + uclass_find_next_device(&dev)) { + ut_assert(dev); + + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1); + ut_assert(uc_pdata->intval2 == TEST_UC_PDATA_INTVAL2); + ut_assert(uc_pdata->intval3 == TEST_UC_PDATA_INTVAL3); + } + + return 0; +} +DM_TEST(dm_test_autobind_uclass_pdata_valid, DM_TESTF_SCAN_PDATA); + /* Test that autoprobe finds all the expected devices */ static int dm_test_autoprobe(struct dm_test_state *dms) { diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c index 7cb37f7..4ae75ef 100644 --- a/test/dm/test-uclass.c +++ b/test/dm/test-uclass.c @@ -30,9 +30,18 @@ int test_ping(struct udevice *dev, int pingval, int *pingret) static int test_post_bind(struct udevice *dev) { + struct dm_test_perdev_uc_pdata *uc_pdata; + dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++; ut_assert(!device_active(dev)); + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + + uc_pdata->intval1 = TEST_UC_PDATA_INTVAL1; + uc_pdata->intval2 = TEST_UC_PDATA_INTVAL2; + uc_pdata->intval3 = TEST_UC_PDATA_INTVAL3; + return 0; } @@ -115,4 +124,6 @@ UCLASS_DRIVER(test) = { .destroy = test_destroy, .priv_auto_alloc_size = sizeof(struct dm_test_uclass_priv), .per_device_auto_alloc_size = sizeof(struct dm_test_uclass_perdev_priv), + .per_device_platdata_auto_alloc_size = + sizeof(struct dm_test_perdev_uc_pdata), }; -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V3 3/4] dm: test: Add tests for device's uclass platform data 2015-04-08 17:06 ` [U-Boot] [PATCH V3 3/4] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak @ 2015-04-09 1:47 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-09 1:47 UTC (permalink / raw) To: u-boot On 8 April 2015 at 11:06, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This test introduces new test structure type:dm_test_perdev_uc_pdata. > The structure consists of three int values only. For the test purposes, > three pattern values are defined by enum, starting with TEST_UC_PDATA_INTVAL1. > > This commit adds two test cases for uclass platform data: > - Test: dm_test_autobind_uclass_pdata_alloc - this tests if: > * uclass driver sets: .per_device_platdata_auto_alloc_size field > * the devices's: dev->uclass_platdata is non-NULL > > - Test: dm_test_autobind_uclass_pdata_valid - this tests: > * if the devices's: dev->uclass_platdata is non-NULL > * the structure of type 'dm_test_perdev_uc_pdata' allocated at address > pointed by dev->uclass_platdata. Each structure field, should be equal > to proper pattern data, starting from .intval1 == TEST_UC_PDATA_INTVAL1. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > Changes V2: > - update test functions with calls: uclass_find_first/next_device() > > Changes V3: > - none > --- > include/dm/test.h | 20 +++++++++++++++++++ > test/dm/core.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ > test/dm/test-uclass.c | 11 +++++++++++ > 3 files changed, 86 insertions(+) Acked-by: Simon Glass <sjg@chromium.org> ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V3 4/4] dm: test: Add tests for get/find uclass devices 2015-04-08 17:06 ` [U-Boot] [PATCH V3 0/4] dm: core: add device's uclass platform data and tests Przemyslaw Marczak ` (2 preceding siblings ...) 2015-04-08 17:06 ` [U-Boot] [PATCH V3 3/4] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak @ 2015-04-08 17:06 ` Przemyslaw Marczak 2015-04-09 1:47 ` Simon Glass 2015-04-09 12:11 ` [U-Boot] [PATCH] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak 5 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-08 17:06 UTC (permalink / raw) To: u-boot This commit introduces simple tests for functions: - uclass_find_first_device() - uclass_find_next_device() - uclass_first_device() - uclass_next_device() Tests added by this commit: - Test: dm_test_uclass_devices_find: * call uclass_find_first_device(), then check if: (dev != NULL), (ret == 0) * for the rest devices, call uclass_find_next_device() and do the same check - Test: dm_test_uclass_devices_get: * call uclass_first_device(), then check if: -- (dev != NULL), (ret == 0), device_active() * for the rest devices, call uclass_next_device() and do the same check Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> Changes V3: - new commit --- test/dm/core.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/test/dm/core.c b/test/dm/core.c index 009ad36..3a8dd1d 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -656,9 +656,41 @@ static int dm_test_uclass_before_ready(struct dm_test_state *dms) return 0; } - DM_TEST(dm_test_uclass_before_ready, 0); +static int dm_test_uclass_devices_find(struct dm_test_state *dms) +{ + struct udevice *dev; + int ret; + + for (ret = uclass_find_first_device(UCLASS_TEST, &dev); + dev; + ret = uclass_find_next_device(&dev)) { + ut_assert(!ret); + ut_assert(dev); + } + + return 0; +} +DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA); + +static int dm_test_uclass_devices_get(struct dm_test_state *dms) +{ + struct udevice *dev; + int ret; + + for (ret = uclass_first_device(UCLASS_TEST, &dev); + dev; + ret = uclass_next_device(&dev)) { + ut_assert(!ret); + ut_assert(dev); + ut_assert(device_active(dev)); + } + + return 0; +} +DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA); + static int dm_test_device_get_uclass_id(struct dm_test_state *dms) { struct udevice *dev; -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V3 4/4] dm: test: Add tests for get/find uclass devices 2015-04-08 17:06 ` [U-Boot] [PATCH V3 4/4] dm: test: Add tests for get/find uclass devices Przemyslaw Marczak @ 2015-04-09 1:47 ` Simon Glass 2015-04-09 6:54 ` Przemyslaw Marczak 0 siblings, 1 reply; 61+ messages in thread From: Simon Glass @ 2015-04-09 1:47 UTC (permalink / raw) To: u-boot On 8 April 2015 at 11:06, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit introduces simple tests for functions: > - uclass_find_first_device() > - uclass_find_next_device() > - uclass_first_device() > - uclass_next_device() > > Tests added by this commit: > - Test: dm_test_uclass_devices_find: > * call uclass_find_first_device(), then check if: (dev != NULL), (ret == 0) > * for the rest devices, call uclass_find_next_device() and do the same check > > - Test: dm_test_uclass_devices_get: > * call uclass_first_device(), then check if: > -- (dev != NULL), (ret == 0), device_active() > * for the rest devices, call uclass_next_device() and do the same check > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > > Changes V3: > - new commit > --- > test/dm/core.c | 34 +++++++++++++++++++++++++++++++++- > 1 file changed, 33 insertions(+), 1 deletion(-) Acked-by: Simon Glass <sjg@chromium.org> See below. > > diff --git a/test/dm/core.c b/test/dm/core.c > index 009ad36..3a8dd1d 100644 > --- a/test/dm/core.c > +++ b/test/dm/core.c > @@ -656,9 +656,41 @@ static int dm_test_uclass_before_ready(struct dm_test_state *dms) > > return 0; > } > - > DM_TEST(dm_test_uclass_before_ready, 0); > > +static int dm_test_uclass_devices_find(struct dm_test_state *dms) > +{ > + struct udevice *dev; > + int ret; > + > + for (ret = uclass_find_first_device(UCLASS_TEST, &dev); > + dev; > + ret = uclass_find_next_device(&dev)) { > + ut_assert(!ret); > + ut_assert(dev); ut_assert(!device_active(dev)); If you like I can add that when I apply. > + } > + > + return 0; > +} > +DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA); > + > +static int dm_test_uclass_devices_get(struct dm_test_state *dms) > +{ > + struct udevice *dev; > + int ret; > + > + for (ret = uclass_first_device(UCLASS_TEST, &dev); > + dev; > + ret = uclass_next_device(&dev)) { > + ut_assert(!ret); > + ut_assert(dev); > + ut_assert(device_active(dev)); > + } > + > + return 0; > +} > +DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA); > + > static int dm_test_device_get_uclass_id(struct dm_test_state *dms) > { > struct udevice *dev; > -- > 1.9.1 > Regards, Simon ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V3 4/4] dm: test: Add tests for get/find uclass devices 2015-04-09 1:47 ` Simon Glass @ 2015-04-09 6:54 ` Przemyslaw Marczak 0 siblings, 0 replies; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-09 6:54 UTC (permalink / raw) To: u-boot Hello Simon, On 04/09/2015 03:47 AM, Simon Glass wrote: > On 8 April 2015 at 11:06, Przemyslaw Marczak <p.marczak@samsung.com> wrote: >> This commit introduces simple tests for functions: >> - uclass_find_first_device() >> - uclass_find_next_device() >> - uclass_first_device() >> - uclass_next_device() >> >> Tests added by this commit: >> - Test: dm_test_uclass_devices_find: >> * call uclass_find_first_device(), then check if: (dev != NULL), (ret == 0) >> * for the rest devices, call uclass_find_next_device() and do the same check >> >> - Test: dm_test_uclass_devices_get: >> * call uclass_first_device(), then check if: >> -- (dev != NULL), (ret == 0), device_active() >> * for the rest devices, call uclass_next_device() and do the same check >> >> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> >> Cc: Simon Glass <sjg@chromium.org> >> >> Changes V3: >> - new commit >> --- >> test/dm/core.c | 34 +++++++++++++++++++++++++++++++++- >> 1 file changed, 33 insertions(+), 1 deletion(-) > > Acked-by: Simon Glass <sjg@chromium.org> > > See below. > >> >> diff --git a/test/dm/core.c b/test/dm/core.c >> index 009ad36..3a8dd1d 100644 >> --- a/test/dm/core.c >> +++ b/test/dm/core.c >> @@ -656,9 +656,41 @@ static int dm_test_uclass_before_ready(struct dm_test_state *dms) >> >> return 0; >> } >> - >> DM_TEST(dm_test_uclass_before_ready, 0); >> >> +static int dm_test_uclass_devices_find(struct dm_test_state *dms) >> +{ >> + struct udevice *dev; >> + int ret; >> + >> + for (ret = uclass_find_first_device(UCLASS_TEST, &dev); >> + dev; >> + ret = uclass_find_next_device(&dev)) { >> + ut_assert(!ret); >> + ut_assert(dev); > > ut_assert(!device_active(dev)); > > If you like I can add that when I apply. > I don't think it's a good idea. Those calls above, don't probe the device, but also don't guarantee that, the returned device was not probed, before the call. >> + } >> + >> + return 0; >> +} >> +DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA); >> + >> +static int dm_test_uclass_devices_get(struct dm_test_state *dms) >> +{ >> + struct udevice *dev; >> + int ret; >> + >> + for (ret = uclass_first_device(UCLASS_TEST, &dev); >> + dev; >> + ret = uclass_next_device(&dev)) { >> + ut_assert(!ret); >> + ut_assert(dev); >> + ut_assert(device_active(dev)); >> + } >> + >> + return 0; >> +} >> +DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA); >> + >> static int dm_test_device_get_uclass_id(struct dm_test_state *dms) >> { >> struct udevice *dev; >> -- >> 1.9.1 >> > > Regards, > Simon > Best regards, -- Przemyslaw Marczak Samsung R&D Institute Poland Samsung Electronics p.marczak at samsung.com ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH] dm: core: remove type 'static' of function uclass_get_device_tail() 2015-04-08 17:06 ` [U-Boot] [PATCH V3 0/4] dm: core: add device's uclass platform data and tests Przemyslaw Marczak ` (3 preceding siblings ...) 2015-04-08 17:06 ` [U-Boot] [PATCH V3 4/4] dm: test: Add tests for get/find uclass devices Przemyslaw Marczak @ 2015-04-09 12:11 ` Przemyslaw Marczak 2015-04-09 12:16 ` Przemyslaw Marczak 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak 5 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-09 12:11 UTC (permalink / raw) To: u-boot Uclass API provides a few functions for get/find the device. To provide a complete function set of uclass-internal functions, for use by the drivers, the function uclass_get_device_tail() should be non-static. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- drivers/core/uclass.c | 2 +- include/dm/uclass-internal.h | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 21ab0d5..fe78cbf 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -249,7 +249,7 @@ static int uclass_find_device_by_of_offset(enum uclass_id id, int node, * @devp: Returns the value of 'dev' if there is no error * @return ret, if non-zero, else the result of the device_probe() call */ -static int uclass_get_device_tail(struct udevice *dev, int ret, +int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp) { if (ret) diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index befbae5..4d8b409 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -11,12 +11,25 @@ #define _DM_UCLASS_INTERNAL_H /** + * uclass_get_device_tail() - handle the end of a get_device call + * + * This handles returning an error or probing a device as needed. + * + * @dev: Device that needs to be probed + * @ret: Error to return. If non-zero then the device is not probed + * @devp: Returns the value of 'dev' if there is no error + * @return ret, if non-zero, else the result of the device_probe() call + */ +int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp); + +/** * uclass_find_device() - Return n-th child of uclass * @id: Id number of the uclass * @index: Position of the child in uclass's list * #devp: Returns pointer to device, or NULL on error * - * The device is not prepared for use - this is an internal function + * The device is not prepared for use - this is an internal function. + * The function uclass_get_device_tail() can be used to probe the device. * * @return the uclass pointer of a child at the given index or * return NULL on error. @@ -28,7 +41,8 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp); * @id: Id number of the uclass * #devp: Returns pointer to device, or NULL on error * - * The device is not prepared for use - this is an internal function + * The device is not prepared for use - this is an internal function. + * The function uclass_get_device_tail() can be used to probe the device. * * @return 0 if OK (found or not found), -1 on error */ @@ -39,7 +53,8 @@ int uclass_find_first_device(enum uclass_id id, struct udevice **devp); * @devp: On entry, pointer to device to lookup. On exit, returns pointer * to the next device in the same uclass, or NULL if none * - * The device is not prepared for use - this is an internal function + * The device is not prepared for use - this is an internal function. + * The function uclass_get_device_tail() can be used to probe the device. * * @return 0 if OK (found or not found), -1 on error */ -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH] dm: core: remove type 'static' of function uclass_get_device_tail() 2015-04-09 12:11 ` [U-Boot] [PATCH] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak @ 2015-04-09 12:16 ` Przemyslaw Marczak 0 siblings, 0 replies; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-09 12:16 UTC (permalink / raw) To: u-boot Hello Simon, On 04/09/2015 02:11 PM, Przemyslaw Marczak wrote: > Uclass API provides a few functions for get/find the device. > To provide a complete function set of uclass-internal functions, > for use by the drivers, the function uclass_get_device_tail() > should be non-static. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > drivers/core/uclass.c | 2 +- > include/dm/uclass-internal.h | 21 ++++++++++++++++++--- > 2 files changed, 19 insertions(+), 4 deletions(-) > This should be also added to the changes, for completeness. Best regards, -- Przemyslaw Marczak Samsung R&D Institute Poland Samsung Electronics p.marczak at samsung.com ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests 2015-04-08 17:06 ` [U-Boot] [PATCH V3 0/4] dm: core: add device's uclass platform data and tests Przemyslaw Marczak ` (4 preceding siblings ...) 2015-04-09 12:11 ` [U-Boot] [PATCH] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak @ 2015-04-15 11:07 ` Przemyslaw Marczak 2015-04-15 11:07 ` [U-Boot] [PATCH V4 01/10] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak ` (10 more replies) 5 siblings, 11 replies; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-15 11:07 UTC (permalink / raw) To: u-boot Hello, Before merge, I would like to extend this patchset by additional functions [V4], which are now the base for my work on PMIC. The base version: The struct udevice provides two fields for device's platform data: - .platdata - to keep platform-dependent data for the device driver - .parent_platdata - to keep platform-dependent data for the device parent Some implementations may need addidional platform data, which could be owned by the uclass. For example, the regulator device's constraints. This patchset adds the additional field: - .uclass_platdata - to keep platform-dependend data for the uclass driver Two tests are added to the test framework: - one for check dev->uclass_platdata pointer - second for validation the data assigned to by test uclass's post_bind() method Change in V2: - implementation of functions for getting the uclass's device without probe it - cleanup test code Change in V3: - add tests for uclass device get/find functions Change in V4: - remove type 'static' for uclass_get_device_tail() - add: class_get/find_device_by_name() with sandbox tests - add: dev_get_driver_ops() - add: dev_get_uclass_name() Przemyslaw Marczak (10): dm: core: add internal functions for getting the device without probe dm: core: Extend struct udevice by '.uclass_platdata' field. dm: test: Add tests for device's uclass platform data dm: test: Add tests for get/find uclass devices dm: core: remove type 'static' of function uclass_get_device_tail() dm: core: uclass: add function: uclass_find_device_by_name() dm: core: uclass: add function: uclass_get_device_by_name() dm: core: device: add function: dev_get_driver_ops() dm: core: device: add function: dev_get_uclass_name() dm: test: Add tests for get/find uclass's device by name drivers/core/device-remove.c | 4 + drivers/core/device.c | 49 ++++++++++++- drivers/core/uclass.c | 96 +++++++++++++++++------- include/dm/device.h | 38 +++++++++- include/dm/test.h | 20 +++++ include/dm/uclass-internal.h | 100 +++++++++++++++++++------ include/dm/uclass.h | 19 +++++ test/dm/core.c | 170 ++++++++++++++++++++++++++++++++++++++++++- test/dm/test-uclass.c | 11 +++ 9 files changed, 451 insertions(+), 56 deletions(-) -- 1.9.1 ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 01/10] dm: core: add internal functions for getting the device without probe 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak @ 2015-04-15 11:07 ` Przemyslaw Marczak 2015-04-20 3:22 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 02/10] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak ` (9 subsequent siblings) 10 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-15 11:07 UTC (permalink / raw) To: u-boot This commit extends the uclass-internal functions by: - uclass_find_first_device() - uclass_find_next_device() For both functions, the returned device is not probed. After some cleanup, the above functions are called by: - uclass_first_device() - uclass_next_device() for which, the returned device is probed. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> Acked-by: Simon Glass <sjg@chromium.org> --- Changes V2: - new commit Changes V3: - none Changes V4: - add Acked-by --- drivers/core/uclass.c | 59 +++++++++++++++++++++++++------------------- include/dm/uclass-internal.h | 22 +++++++++++++++++ 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 98c15e5..21ab0d5 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -156,6 +156,36 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp) return -ENODEV; } +int uclass_find_first_device(enum uclass_id id, struct udevice **devp) +{ + struct uclass *uc; + int ret; + + *devp = NULL; + ret = uclass_get(id, &uc); + if (ret) + return ret; + if (list_empty(&uc->dev_head)) + return 0; + + *devp = list_first_entry(&uc->dev_head, struct udevice, uclass_node); + + return 0; +} + +int uclass_find_next_device(struct udevice **devp) +{ + struct udevice *dev = *devp; + + *devp = NULL; + if (list_is_last(&dev->uclass_node, &dev->uclass->dev_head)) + return 0; + + *devp = list_entry(dev->uclass_node.next, struct udevice, uclass_node); + + return 0; +} + int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, bool find_req_seq, struct udevice **devp) { @@ -274,24 +304,12 @@ int uclass_get_device_by_of_offset(enum uclass_id id, int node, int uclass_first_device(enum uclass_id id, struct udevice **devp) { - struct uclass *uc; struct udevice *dev; int ret; *devp = NULL; - ret = uclass_get(id, &uc); - if (ret) - return ret; - if (list_empty(&uc->dev_head)) - return 0; - - dev = list_first_entry(&uc->dev_head, struct udevice, uclass_node); - ret = device_probe(dev); - if (ret) - return ret; - *devp = dev; - - return 0; + ret = uclass_find_first_device(id, &dev); + return uclass_get_device_tail(dev, ret, devp); } int uclass_next_device(struct udevice **devp) @@ -300,17 +318,8 @@ int uclass_next_device(struct udevice **devp) int ret; *devp = NULL; - if (list_is_last(&dev->uclass_node, &dev->uclass->dev_head)) - return 0; - - dev = list_entry(dev->uclass_node.next, struct udevice, - uclass_node); - ret = device_probe(dev); - if (ret) - return ret; - *devp = dev; - - return 0; + ret = uclass_find_next_device(&dev); + return uclass_get_device_tail(dev, ret, devp); } int uclass_bind_device(struct udevice *dev) diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index ae2a93d..befbae5 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -24,6 +24,28 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp); /** + * uclass_find_first_device() - Return the first device in a uclass + * @id: Id number of the uclass + * #devp: Returns pointer to device, or NULL on error + * + * The device is not prepared for use - this is an internal function + * + * @return 0 if OK (found or not found), -1 on error + */ +int uclass_find_first_device(enum uclass_id id, struct udevice **devp); + +/** + * uclass_find_next_device() - Return the next device in a uclass + * @devp: On entry, pointer to device to lookup. On exit, returns pointer + * to the next device in the same uclass, or NULL if none + * + * The device is not prepared for use - this is an internal function + * + * @return 0 if OK (found or not found), -1 on error + */ +int uclass_find_next_device(struct udevice **devp); + +/** * uclass_bind_device() - Associate device with a uclass * * Connect the device into uclass's list of devices. -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 01/10] dm: core: add internal functions for getting the device without probe 2015-04-15 11:07 ` [U-Boot] [PATCH V4 01/10] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak @ 2015-04-20 3:22 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-20 3:22 UTC (permalink / raw) To: u-boot On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit extends the uclass-internal functions by: > - uclass_find_first_device() > - uclass_find_next_device() > For both functions, the returned device is not probed. > > After some cleanup, the above functions are called by: > - uclass_first_device() > - uclass_next_device() > for which, the returned device is probed. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > Acked-by: Simon Glass <sjg@chromium.org> > --- > Changes V2: > - new commit > > Changes V3: > - none > > Changes V4: > - add Acked-by > --- > drivers/core/uclass.c | 59 +++++++++++++++++++++++++------------------- > include/dm/uclass-internal.h | 22 +++++++++++++++++ > 2 files changed, 56 insertions(+), 25 deletions(-) Applied to u-boot-dm, thanks! ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 02/10] dm: core: Extend struct udevice by '.uclass_platdata' field. 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak 2015-04-15 11:07 ` [U-Boot] [PATCH V4 01/10] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak @ 2015-04-15 11:07 ` Przemyslaw Marczak 2015-04-20 3:22 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 03/10] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak ` (8 subsequent siblings) 10 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-15 11:07 UTC (permalink / raw) To: u-boot This commit adds 'uclass_platdata' field to 'struct udevice', which can be automatically allocated at bind. The allocation size is defined in 'struct uclass_driver' as 'per_device_platdata_auto_alloc_size'. New device's flag is added: DM_FLAG_ALLOC_UCLASS_PDATA, which is used for memory freeing at device unbind method. As for other udevice's fields, a complementary function is added: - dev_get_uclass_platdata() Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> Acked-by: Simon Glass <sjg@chromium.org> --- Changes V2: - none Changes V3: - none Changes V4: - add Acked-by --- drivers/core/device-remove.c | 4 ++++ drivers/core/device.c | 33 +++++++++++++++++++++++++++++---- include/dm/device.h | 17 ++++++++++++++++- include/dm/uclass.h | 4 ++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 7fee1c0..6a16b4f 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -92,6 +92,10 @@ int device_unbind(struct udevice *dev) free(dev->platdata); dev->platdata = NULL; } + if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { + free(dev->uclass_platdata); + dev->uclass_platdata = NULL; + } if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { free(dev->parent_platdata); dev->parent_platdata = NULL; diff --git a/drivers/core/device.c b/drivers/core/device.c index ccaa99c..80eb55b 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -30,7 +30,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, { struct udevice *dev; struct uclass *uc; - int ret = 0; + int size, ret = 0; *devp = NULL; if (!name) @@ -79,9 +79,19 @@ int device_bind(struct udevice *parent, const struct driver *drv, goto fail_alloc1; } } - if (parent) { - int size = parent->driver->per_child_platdata_auto_alloc_size; + size = uc->uc_drv->per_device_platdata_auto_alloc_size; + if (size) { + dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA; + dev->uclass_platdata = calloc(1, size); + if (!dev->uclass_platdata) { + ret = -ENOMEM; + goto fail_alloc2; + } + } + + if (parent) { + size = parent->driver->per_child_platdata_auto_alloc_size; if (!size) { size = parent->uclass->uc_drv-> per_child_platdata_auto_alloc_size; @@ -91,7 +101,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, dev->parent_platdata = calloc(1, size); if (!dev->parent_platdata) { ret = -ENOMEM; - goto fail_alloc2; + goto fail_alloc3; } } } @@ -139,6 +149,11 @@ fail_uclass_bind: free(dev->parent_platdata); dev->parent_platdata = NULL; } +fail_alloc3: + if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { + free(dev->uclass_platdata); + dev->uclass_platdata = NULL; + } fail_alloc2: if (dev->flags & DM_FLAG_ALLOC_PDATA) { free(dev->platdata); @@ -314,6 +329,16 @@ void *dev_get_parent_platdata(struct udevice *dev) return dev->parent_platdata; } +void *dev_get_uclass_platdata(struct udevice *dev) +{ + if (!dev) { + dm_warn("%s: null device", __func__); + return NULL; + } + + return dev->uclass_platdata; +} + void *dev_get_priv(struct udevice *dev) { if (!dev) { diff --git a/include/dm/device.h b/include/dm/device.h index c11342c..ad002fe 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -30,8 +30,11 @@ struct driver_info; /* DM is responsible for allocating and freeing parent_platdata */ #define DM_FLAG_ALLOC_PARENT_PDATA (1 << 3) +/* DM is responsible for allocating and freeing uclass_platdata */ +#define DM_FLAG_ALLOC_UCLASS_PDATA (1 << 4) + /* Allocate driver private data on a DMA boundary */ -#define DM_FLAG_ALLOC_PRIV_DMA (1 << 4) +#define DM_FLAG_ALLOC_PRIV_DMA (1 << 5) /** * struct udevice - An instance of a driver @@ -54,6 +57,7 @@ struct driver_info; * @name: Name of device, typically the FDT node name * @platdata: Configuration data for this device * @parent_platdata: The parent bus's configuration data for this device + * @uclass_platdata: The uclass's configuration data for this device * @of_offset: Device tree node offset for this device (- for none) * @driver_data: Driver data word for the entry that matched this device with * its driver @@ -75,6 +79,7 @@ struct udevice { const char *name; void *platdata; void *parent_platdata; + void *uclass_platdata; int of_offset; ulong driver_data; struct udevice *parent; @@ -210,6 +215,16 @@ void *dev_get_platdata(struct udevice *dev); void *dev_get_parent_platdata(struct udevice *dev); /** + * dev_get_uclass_platdata() - Get the uclass platform data for a device + * + * This checks that dev is not NULL, but no other checks for now + * + * @dev Device to check + * @return uclass's platform data, or NULL if none + */ +void *dev_get_uclass_platdata(struct udevice *dev); + +/** * dev_get_parentdata() - Get the parent data for a device * * The parent data is data stored in the device but owned by the parent. diff --git a/include/dm/uclass.h b/include/dm/uclass.h index d57d804..b271472 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -65,6 +65,9 @@ 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_device_platdata_auto_alloc_size: Each device can hold platform data + * owned by the uclass as 'dev->uclass_platdata'. If the value is non-zero, + * then this will be automatically allocated. * @per_child_auto_alloc_size: Each child device (of a parent in this * uclass) can hold parent data for the device/uclass. This value is only * used as a falback if this member is 0 in the driver. @@ -90,6 +93,7 @@ struct uclass_driver { int (*destroy)(struct uclass *class); int priv_auto_alloc_size; int per_device_auto_alloc_size; + int per_device_platdata_auto_alloc_size; int per_child_auto_alloc_size; int per_child_platdata_auto_alloc_size; const void *ops; -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 02/10] dm: core: Extend struct udevice by '.uclass_platdata' field. 2015-04-15 11:07 ` [U-Boot] [PATCH V4 02/10] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak @ 2015-04-20 3:22 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-20 3:22 UTC (permalink / raw) To: u-boot On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit adds 'uclass_platdata' field to 'struct udevice', which > can be automatically allocated at bind. The allocation size is defined > in 'struct uclass_driver' as 'per_device_platdata_auto_alloc_size'. > > New device's flag is added: DM_FLAG_ALLOC_UCLASS_PDATA, which is used > for memory freeing at device unbind method. > > As for other udevice's fields, a complementary function is added: > - dev_get_uclass_platdata() > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > Acked-by: Simon Glass <sjg@chromium.org> > --- > Changes V2: > - none > > Changes V3: > - none > > Changes V4: > - add Acked-by Applied to u-boot-dm, thanks! ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 03/10] dm: test: Add tests for device's uclass platform data 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak 2015-04-15 11:07 ` [U-Boot] [PATCH V4 01/10] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak 2015-04-15 11:07 ` [U-Boot] [PATCH V4 02/10] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak @ 2015-04-15 11:07 ` Przemyslaw Marczak 2015-04-20 3:22 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 04/10] dm: test: Add tests for get/find uclass devices Przemyslaw Marczak ` (7 subsequent siblings) 10 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-15 11:07 UTC (permalink / raw) To: u-boot This test introduces new test structure type:dm_test_perdev_uc_pdata. The structure consists of three int values only. For the test purposes, three pattern values are defined by enum, starting with TEST_UC_PDATA_INTVAL1. This commit adds two test cases for uclass platform data: - Test: dm_test_autobind_uclass_pdata_alloc - this tests if: * uclass driver sets: .per_device_platdata_auto_alloc_size field * the devices's: dev->uclass_platdata is non-NULL - Test: dm_test_autobind_uclass_pdata_valid - this tests: * if the devices's: dev->uclass_platdata is non-NULL * the structure of type 'dm_test_perdev_uc_pdata' allocated at address pointed by dev->uclass_platdata. Each structure field, should be equal to proper pattern data, starting from .intval1 == TEST_UC_PDATA_INTVAL1. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> Acked-by: Simon Glass <sjg@chromium.org> --- Changes V2: - update test functions with calls: uclass_find_first/next_device() Changes V3: - none Changes V4: - add Acked-by --- include/dm/test.h | 20 +++++++++++++++++++ test/dm/core.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/dm/test-uclass.c | 11 +++++++++++ 3 files changed, 86 insertions(+) diff --git a/include/dm/test.h b/include/dm/test.h index 9c4b8d3..f03fbcb 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -98,6 +98,26 @@ struct dm_test_parent_data { int flag; }; +/* Test values for test device's uclass platform data */ +enum { + TEST_UC_PDATA_INTVAL1 = 2, + TEST_UC_PDATA_INTVAL2 = 334, + TEST_UC_PDATA_INTVAL3 = 789452, +}; + +/** + * struct dm_test_uclass_platda - uclass's information on each device + * + * @intval1: set to TEST_UC_PDATA_INTVAL1 in .post_bind method of test uclass + * @intval2: set to TEST_UC_PDATA_INTVAL2 in .post_bind method of test uclass + * @intval3: set to TEST_UC_PDATA_INTVAL3 in .post_bind method of test uclass + */ +struct dm_test_perdev_uc_pdata { + int intval1; + int intval2; + int intval3; +}; + /* * Operation counts for the test driver, used to check that each method is * called correctly diff --git a/test/dm/core.c b/test/dm/core.c index 990d390..009ad36 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -129,6 +129,61 @@ static int dm_test_autobind(struct dm_test_state *dms) } DM_TEST(dm_test_autobind, 0); +/* Test that binding with uclass platdata allocation occurs correctly */ +static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) +{ + struct dm_test_perdev_uc_pdata *uc_pdata; + struct udevice *dev; + struct uclass *uc; + + ut_assertok(uclass_get(UCLASS_TEST, &uc)); + ut_assert(uc); + + /** + * Test if test uclass driver requires allocation for the uclass + * platform data and then check the dev->uclass_platdata pointer. + */ + ut_assert(uc->uc_drv->per_device_platdata_auto_alloc_size); + + for (uclass_find_first_device(UCLASS_TEST, &dev); + dev; + uclass_find_next_device(&dev)) { + ut_assert(dev); + + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + } + + return 0; +} +DM_TEST(dm_test_autobind_uclass_pdata_alloc, DM_TESTF_SCAN_PDATA); + +/* Test that binding with uclass platdata setting occurs correctly */ +static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) +{ + struct dm_test_perdev_uc_pdata *uc_pdata; + struct udevice *dev; + + /** + * In the test_postbind() method of test uclass driver, the uclass + * platform data should be set to three test int values - test it. + */ + for (uclass_find_first_device(UCLASS_TEST, &dev); + dev; + uclass_find_next_device(&dev)) { + ut_assert(dev); + + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1); + ut_assert(uc_pdata->intval2 == TEST_UC_PDATA_INTVAL2); + ut_assert(uc_pdata->intval3 == TEST_UC_PDATA_INTVAL3); + } + + return 0; +} +DM_TEST(dm_test_autobind_uclass_pdata_valid, DM_TESTF_SCAN_PDATA); + /* Test that autoprobe finds all the expected devices */ static int dm_test_autoprobe(struct dm_test_state *dms) { diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c index 7cb37f7..4ae75ef 100644 --- a/test/dm/test-uclass.c +++ b/test/dm/test-uclass.c @@ -30,9 +30,18 @@ int test_ping(struct udevice *dev, int pingval, int *pingret) static int test_post_bind(struct udevice *dev) { + struct dm_test_perdev_uc_pdata *uc_pdata; + dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++; ut_assert(!device_active(dev)); + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + + uc_pdata->intval1 = TEST_UC_PDATA_INTVAL1; + uc_pdata->intval2 = TEST_UC_PDATA_INTVAL2; + uc_pdata->intval3 = TEST_UC_PDATA_INTVAL3; + return 0; } @@ -115,4 +124,6 @@ UCLASS_DRIVER(test) = { .destroy = test_destroy, .priv_auto_alloc_size = sizeof(struct dm_test_uclass_priv), .per_device_auto_alloc_size = sizeof(struct dm_test_uclass_perdev_priv), + .per_device_platdata_auto_alloc_size = + sizeof(struct dm_test_perdev_uc_pdata), }; -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 03/10] dm: test: Add tests for device's uclass platform data 2015-04-15 11:07 ` [U-Boot] [PATCH V4 03/10] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak @ 2015-04-20 3:22 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-20 3:22 UTC (permalink / raw) To: u-boot On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This test introduces new test structure type:dm_test_perdev_uc_pdata. > The structure consists of three int values only. For the test purposes, > three pattern values are defined by enum, starting with TEST_UC_PDATA_INTVAL1. > > This commit adds two test cases for uclass platform data: > - Test: dm_test_autobind_uclass_pdata_alloc - this tests if: > * uclass driver sets: .per_device_platdata_auto_alloc_size field > * the devices's: dev->uclass_platdata is non-NULL > > - Test: dm_test_autobind_uclass_pdata_valid - this tests: > * if the devices's: dev->uclass_platdata is non-NULL > * the structure of type 'dm_test_perdev_uc_pdata' allocated at address > pointed by dev->uclass_platdata. Each structure field, should be equal > to proper pattern data, starting from .intval1 == TEST_UC_PDATA_INTVAL1. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > Acked-by: Simon Glass <sjg@chromium.org> > --- > Changes V2: > - update test functions with calls: uclass_find_first/next_device() > > Changes V3: > - none > > Changes V4: > - add Acked-by Applied to u-boot-dm, thanks! ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 04/10] dm: test: Add tests for get/find uclass devices 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak ` (2 preceding siblings ...) 2015-04-15 11:07 ` [U-Boot] [PATCH V4 03/10] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak @ 2015-04-15 11:07 ` Przemyslaw Marczak 2015-04-20 3:22 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 05/10] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak ` (6 subsequent siblings) 10 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-15 11:07 UTC (permalink / raw) To: u-boot This commit introduces simple tests for functions: - uclass_find_first_device() - uclass_find_next_device() - uclass_first_device() - uclass_next_device() Tests added by this commit: - Test: dm_test_uclass_devices_find: * call uclass_find_first_device(), then check if: (dev != NULL), (ret == 0) * for the rest devices, call uclass_find_next_device() and do the same check - Test: dm_test_uclass_devices_get: * call uclass_first_device(), then check if: -- (dev != NULL), (ret == 0), device_active() * for the rest devices, call uclass_next_device() and do the same check Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> Acked-by: Simon Glass <sjg@chromium.org> --- Changes V3: - new commit Changes V4: - add Acked-by --- test/dm/core.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/test/dm/core.c b/test/dm/core.c index 009ad36..3a8dd1d 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -656,9 +656,41 @@ static int dm_test_uclass_before_ready(struct dm_test_state *dms) return 0; } - DM_TEST(dm_test_uclass_before_ready, 0); +static int dm_test_uclass_devices_find(struct dm_test_state *dms) +{ + struct udevice *dev; + int ret; + + for (ret = uclass_find_first_device(UCLASS_TEST, &dev); + dev; + ret = uclass_find_next_device(&dev)) { + ut_assert(!ret); + ut_assert(dev); + } + + return 0; +} +DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA); + +static int dm_test_uclass_devices_get(struct dm_test_state *dms) +{ + struct udevice *dev; + int ret; + + for (ret = uclass_first_device(UCLASS_TEST, &dev); + dev; + ret = uclass_next_device(&dev)) { + ut_assert(!ret); + ut_assert(dev); + ut_assert(device_active(dev)); + } + + return 0; +} +DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA); + static int dm_test_device_get_uclass_id(struct dm_test_state *dms) { struct udevice *dev; -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 04/10] dm: test: Add tests for get/find uclass devices 2015-04-15 11:07 ` [U-Boot] [PATCH V4 04/10] dm: test: Add tests for get/find uclass devices Przemyslaw Marczak @ 2015-04-20 3:22 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-20 3:22 UTC (permalink / raw) To: u-boot On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit introduces simple tests for functions: > - uclass_find_first_device() > - uclass_find_next_device() > - uclass_first_device() > - uclass_next_device() > > Tests added by this commit: > - Test: dm_test_uclass_devices_find: > * call uclass_find_first_device(), then check if: (dev != NULL), (ret == 0) > * for the rest devices, call uclass_find_next_device() and do the same check > > - Test: dm_test_uclass_devices_get: > * call uclass_first_device(), then check if: > -- (dev != NULL), (ret == 0), device_active() > * for the rest devices, call uclass_next_device() and do the same check > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > Acked-by: Simon Glass <sjg@chromium.org> > --- > Changes V3: > - new commit > > Changes V4: > - add Acked-by Applied to u-boot-dm, thanks! ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 05/10] dm: core: remove type 'static' of function uclass_get_device_tail() 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak ` (3 preceding siblings ...) 2015-04-15 11:07 ` [U-Boot] [PATCH V4 04/10] dm: test: Add tests for get/find uclass devices Przemyslaw Marczak @ 2015-04-15 11:07 ` Przemyslaw Marczak 2015-04-20 2:03 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 06/10] dm: core: uclass: add function: uclass_find_device_by_name() Przemyslaw Marczak ` (5 subsequent siblings) 10 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-15 11:07 UTC (permalink / raw) To: u-boot Uclass API provides a few functions for get/find the device. To provide a complete function set of uclass-internal functions, for use by the drivers, the function uclass_get_device_tail() should be non-static. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V4: - new commit --- drivers/core/uclass.c | 2 +- include/dm/uclass-internal.h | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 21ab0d5..fe78cbf 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -249,7 +249,7 @@ static int uclass_find_device_by_of_offset(enum uclass_id id, int node, * @devp: Returns the value of 'dev' if there is no error * @return ret, if non-zero, else the result of the device_probe() call */ -static int uclass_get_device_tail(struct udevice *dev, int ret, +int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp) { if (ret) diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index befbae5..4d8b409 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -11,12 +11,25 @@ #define _DM_UCLASS_INTERNAL_H /** + * uclass_get_device_tail() - handle the end of a get_device call + * + * This handles returning an error or probing a device as needed. + * + * @dev: Device that needs to be probed + * @ret: Error to return. If non-zero then the device is not probed + * @devp: Returns the value of 'dev' if there is no error + * @return ret, if non-zero, else the result of the device_probe() call + */ +int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp); + +/** * uclass_find_device() - Return n-th child of uclass * @id: Id number of the uclass * @index: Position of the child in uclass's list * #devp: Returns pointer to device, or NULL on error * - * The device is not prepared for use - this is an internal function + * The device is not prepared for use - this is an internal function. + * The function uclass_get_device_tail() can be used to probe the device. * * @return the uclass pointer of a child at the given index or * return NULL on error. @@ -28,7 +41,8 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp); * @id: Id number of the uclass * #devp: Returns pointer to device, or NULL on error * - * The device is not prepared for use - this is an internal function + * The device is not prepared for use - this is an internal function. + * The function uclass_get_device_tail() can be used to probe the device. * * @return 0 if OK (found or not found), -1 on error */ @@ -39,7 +53,8 @@ int uclass_find_first_device(enum uclass_id id, struct udevice **devp); * @devp: On entry, pointer to device to lookup. On exit, returns pointer * to the next device in the same uclass, or NULL if none * - * The device is not prepared for use - this is an internal function + * The device is not prepared for use - this is an internal function. + * The function uclass_get_device_tail() can be used to probe the device. * * @return 0 if OK (found or not found), -1 on error */ -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 05/10] dm: core: remove type 'static' of function uclass_get_device_tail() 2015-04-15 11:07 ` [U-Boot] [PATCH V4 05/10] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak @ 2015-04-20 2:03 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-20 2:03 UTC (permalink / raw) To: u-boot On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > Uclass API provides a few functions for get/find the device. > To provide a complete function set of uclass-internal functions, > for use by the drivers, the function uclass_get_device_tail() > should be non-static. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > Changes V4: > - new commit > --- > drivers/core/uclass.c | 2 +- > include/dm/uclass-internal.h | 21 ++++++++++++++++++--- > 2 files changed, 19 insertions(+), 4 deletions(-) > > diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c > index 21ab0d5..fe78cbf 100644 > --- a/drivers/core/uclass.c > +++ b/drivers/core/uclass.c > @@ -249,7 +249,7 @@ static int uclass_find_device_by_of_offset(enum uclass_id id, int node, > * @devp: Returns the value of 'dev' if there is no error > * @return ret, if non-zero, else the result of the device_probe() call > */ You should remove the comment here, since you add it to the header. > -static int uclass_get_device_tail(struct udevice *dev, int ret, > +int uclass_get_device_tail(struct udevice *dev, int ret, > struct udevice **devp) > { > if (ret) > diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h > index befbae5..4d8b409 100644 > --- a/include/dm/uclass-internal.h > +++ b/include/dm/uclass-internal.h > @@ -11,12 +11,25 @@ > #define _DM_UCLASS_INTERNAL_H > > /** > + * uclass_get_device_tail() - handle the end of a get_device call > + * > + * This handles returning an error or probing a device as needed. > + * > + * @dev: Device that needs to be probed > + * @ret: Error to return. If non-zero then the device is not probed > + * @devp: Returns the value of 'dev' if there is no error > + * @return ret, if non-zero, else the result of the device_probe() call > + */ > +int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp); > + > +/** > * uclass_find_device() - Return n-th child of uclass > * @id: Id number of the uclass > * @index: Position of the child in uclass's list > * #devp: Returns pointer to device, or NULL on error > * > - * The device is not prepared for use - this is an internal function > + * The device is not prepared for use - this is an internal function. > + * The function uclass_get_device_tail() can be used to probe the device. > * > * @return the uclass pointer of a child at the given index or > * return NULL on error. > @@ -28,7 +41,8 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp); > * @id: Id number of the uclass > * #devp: Returns pointer to device, or NULL on error > * > - * The device is not prepared for use - this is an internal function > + * The device is not prepared for use - this is an internal function. > + * The function uclass_get_device_tail() can be used to probe the device. > * > * @return 0 if OK (found or not found), -1 on error > */ > @@ -39,7 +53,8 @@ int uclass_find_first_device(enum uclass_id id, struct udevice **devp); > * @devp: On entry, pointer to device to lookup. On exit, returns pointer > * to the next device in the same uclass, or NULL if none > * > - * The device is not prepared for use - this is an internal function > + * The device is not prepared for use - this is an internal function. > + * The function uclass_get_device_tail() can be used to probe the device. > * > * @return 0 if OK (found or not found), -1 on error > */ > -- > 1.9.1 > Regards, Simon ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 06/10] dm: core: uclass: add function: uclass_find_device_by_name() 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak ` (4 preceding siblings ...) 2015-04-15 11:07 ` [U-Boot] [PATCH V4 05/10] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak @ 2015-04-15 11:07 ` Przemyslaw Marczak 2015-04-19 13:23 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 07/10] dm: core: uclass: add function: uclass_get_device_by_name() Przemyslaw Marczak ` (4 subsequent siblings) 10 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-15 11:07 UTC (permalink / raw) To: u-boot This commit extends the driver model uclass's API by function: - uclass_find_device_by_name() And this function returns the device if: - uclass with given ID, exists, - device with exactly given name(dev->name), exists. The returned device is not activated - need to be probed before use. Note: This function returns the first device, which name is equal to the given one. This means, that using this function you must assume, that the device name is unique in the given uclass's ID device list. uclass-internal.h: cleanup - move the uclass_find_device_by_seq() declaration and description, near the other uclass_find*() functions. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V4: - new commit --- drivers/core/uclass.c | 24 +++++++++++++++++ include/dm/uclass-internal.h | 61 +++++++++++++++++++++++++++----------------- 2 files changed, 62 insertions(+), 23 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index fe78cbf..219d765 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -186,6 +186,30 @@ int uclass_find_next_device(struct udevice **devp) return 0; } +int uclass_find_device_by_name(enum uclass_id id, const char *name, + struct udevice **devp) +{ + struct uclass *uc; + struct udevice *dev; + int ret; + + *devp = NULL; + if (!name) + return -EINVAL; + ret = uclass_get(id, &uc); + if (ret) + return ret; + + list_for_each_entry(dev, &uc->dev_head, uclass_node) { + if (!strncmp(dev->name, name, strlen(name))) { + *devp = dev; + return 0; + } + } + + return -ENODEV; +} + int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, bool find_req_seq, struct udevice **devp) { diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index 4d8b409..153f2a7 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -61,6 +61,44 @@ int uclass_find_first_device(enum uclass_id id, struct udevice **devp); int uclass_find_next_device(struct udevice **devp); /** + * uclass_find_device_by_name() - Find uclass device based on ID and name + * + * This searches for a device with the given name. + * + * The device is NOT probed, it is merely returned. + * + * @id: ID to look up + * @name: name of a device to find + * @devp: Returns pointer to device (the first one with the name) + * @return 0 if OK, -ve on error + */ +int uclass_find_device_by_name(enum uclass_id id, const char *name, + struct udevice **devp); + +/** + * uclass_find_device_by_seq() - Find uclass device based on ID and sequence + * + * This searches for a device with the given seq or req_seq. + * + * For seq, if an active device has this sequence it will be returned. + * If there is no such device then this will return -ENODEV. + * + * For req_seq, if a device (whether activated or not) has this req_seq + * value, that device will be returned. This is a strong indication that + * the device will receive that sequence when activated. + * + * The device is NOT probed, it is merely returned. + * + * @id: ID to look up + * @seq_or_req_seq: Sequence number to find (0=first) + * @find_req_seq: true to find req_seq, false to find seq + * @devp: Returns pointer to device (there is only one per for each seq) + * @return 0 if OK, -ve on error + */ +int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, + bool find_req_seq, struct udevice **devp); + +/** * uclass_bind_device() - Associate device with a uclass * * Connect the device into uclass's list of devices. @@ -131,27 +169,4 @@ struct uclass *uclass_find(enum uclass_id key); */ int uclass_destroy(struct uclass *uc); -/** - * uclass_find_device_by_seq() - Find uclass device based on ID and sequence - * - * This searches for a device with the given seq or req_seq. - * - * For seq, if an active device has this sequence it will be returned. - * If there is no such device then this will return -ENODEV. - * - * For req_seq, if a device (whether activated or not) has this req_seq - * value, that device will be returned. This is a strong indication that - * the device will receive that sequence when activated. - * - * The device is NOT probed, it is merely returned. - * - * @id: ID to look up - * @seq_or_req_seq: Sequence number to find (0=first) - * @find_req_seq: true to find req_seq, false to find seq - * @devp: Returns pointer to device (there is only one per for each seq) - * @return 0 if OK, -ve on error - */ -int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, - bool find_req_seq, struct udevice **devp); - #endif -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 06/10] dm: core: uclass: add function: uclass_find_device_by_name() 2015-04-15 11:07 ` [U-Boot] [PATCH V4 06/10] dm: core: uclass: add function: uclass_find_device_by_name() Przemyslaw Marczak @ 2015-04-19 13:23 ` Simon Glass 2015-04-20 3:22 ` Simon Glass 0 siblings, 1 reply; 61+ messages in thread From: Simon Glass @ 2015-04-19 13:23 UTC (permalink / raw) To: u-boot Hi Przemyslaw, On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit extends the driver model uclass's API by function: > - uclass_find_device_by_name() > > And this function returns the device if: > - uclass with given ID, exists, > - device with exactly given name(dev->name), exists. > > The returned device is not activated - need to be probed before use. > > Note: > This function returns the first device, which name is equal > to the given one. This means, that using this function you must > assume, that the device name is unique in the given uclass's ID > device list. > > uclass-internal.h: cleanup - move the uclass_find_device_by_seq() > declaration and description, near the other uclass_find*() functions. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> This uses strncmp() so I thing the function comment should say that it searches only for the part of the name provided. But I suppose this is a minor point. Acked-by: Simon Glass <sjg@chromium.org> Regards, Simon ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 06/10] dm: core: uclass: add function: uclass_find_device_by_name() 2015-04-19 13:23 ` Simon Glass @ 2015-04-20 3:22 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-20 3:22 UTC (permalink / raw) To: u-boot On 19 April 2015 at 07:23, Simon Glass <sjg@chromium.org> wrote: > Hi Przemyslaw, > > On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: >> This commit extends the driver model uclass's API by function: >> - uclass_find_device_by_name() >> >> And this function returns the device if: >> - uclass with given ID, exists, >> - device with exactly given name(dev->name), exists. >> >> The returned device is not activated - need to be probed before use. >> >> Note: >> This function returns the first device, which name is equal >> to the given one. This means, that using this function you must >> assume, that the device name is unique in the given uclass's ID >> device list. >> >> uclass-internal.h: cleanup - move the uclass_find_device_by_seq() >> declaration and description, near the other uclass_find*() functions. >> >> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> >> Cc: Simon Glass <sjg@chromium.org> > > This uses strncmp() so I thing the function comment should say that it > searches only for the part of the name provided. But I suppose this is > a minor point. > > Acked-by: Simon Glass <sjg@chromium.org> > > Regards, > Simon Applied to u-boot-dm, thanks! ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 07/10] dm: core: uclass: add function: uclass_get_device_by_name() 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak ` (5 preceding siblings ...) 2015-04-15 11:07 ` [U-Boot] [PATCH V4 06/10] dm: core: uclass: add function: uclass_find_device_by_name() Przemyslaw Marczak @ 2015-04-15 11:07 ` Przemyslaw Marczak 2015-04-19 13:23 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 08/10] dm: core: device: add function: dev_get_driver_ops() Przemyslaw Marczak ` (3 subsequent siblings) 10 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-15 11:07 UTC (permalink / raw) To: u-boot This commit extends the driver model uclass's API by function: - uclass_get_device_by_name() And this function returns the device if: - uclass with given ID, exists, - device with exactly given name(dev->name), exists, - device probe, doesn't return an error. The returned device is activated and ready to use. Note: This function returns the first device, which name is equal to the given one. This means, that using this function you must assume, that the device name is unique in the given uclass's ID device list. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V4: - new commit --- drivers/core/uclass.c | 11 +++++++++++ include/dm/uclass.h | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 219d765..a139134 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -298,6 +298,17 @@ int uclass_get_device(enum uclass_id id, int index, struct udevice **devp) return uclass_get_device_tail(dev, ret, devp); } +int uclass_get_device_by_name(enum uclass_id id, const char *name, + struct udevice **devp) +{ + struct udevice *dev; + int ret; + + *devp = NULL; + ret = uclass_find_device_by_name(id, name, &dev); + return uclass_get_device_tail(dev, ret, devp); +} + int uclass_get_device_by_seq(enum uclass_id id, int seq, struct udevice **devp) { struct udevice *dev; diff --git a/include/dm/uclass.h b/include/dm/uclass.h index b271472..66e0ea5 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -130,6 +130,21 @@ int uclass_get(enum uclass_id key, struct uclass **ucp); int uclass_get_device(enum uclass_id id, int index, struct udevice **devp); /** + * uclass_get_device_by_name() - Get a uclass device by it's name + * + * This searches the devices in the uclass for one with the given name. + * + * The device is probed to activate it ready for use. + * + * @id: ID to look up + * @name: name of a device to get + * @devp: Returns pointer to device (the first one with the name) + * @return 0 if OK, -ve on error + */ +int uclass_get_device_by_name(enum uclass_id id, const char *name, + struct udevice **devp); + +/** * uclass_get_device_by_seq() - Get a uclass device based on an ID and sequence * * If an active device has this sequence it will be returned. If there is no -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 07/10] dm: core: uclass: add function: uclass_get_device_by_name() 2015-04-15 11:07 ` [U-Boot] [PATCH V4 07/10] dm: core: uclass: add function: uclass_get_device_by_name() Przemyslaw Marczak @ 2015-04-19 13:23 ` Simon Glass 2015-04-20 3:22 ` Simon Glass 0 siblings, 1 reply; 61+ messages in thread From: Simon Glass @ 2015-04-19 13:23 UTC (permalink / raw) To: u-boot On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit extends the driver model uclass's API by function: > - uclass_get_device_by_name() > > And this function returns the device if: > - uclass with given ID, exists, > - device with exactly given name(dev->name), exists, > - device probe, doesn't return an error. > > The returned device is activated and ready to use. > > Note: > This function returns the first device, which name is equal > to the given one. This means, that using this function you must > assume, that the device name is unique in the given uclass's ID > device list. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > Changes V4: > - new commit > --- > drivers/core/uclass.c | 11 +++++++++++ > include/dm/uclass.h | 15 +++++++++++++++ > 2 files changed, 26 insertions(+) Acked-by: Simon Glass <sjg@chromium.org> ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 07/10] dm: core: uclass: add function: uclass_get_device_by_name() 2015-04-19 13:23 ` Simon Glass @ 2015-04-20 3:22 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-20 3:22 UTC (permalink / raw) To: u-boot On 19 April 2015 at 07:23, Simon Glass <sjg@chromium.org> wrote: > On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: >> This commit extends the driver model uclass's API by function: >> - uclass_get_device_by_name() >> >> And this function returns the device if: >> - uclass with given ID, exists, >> - device with exactly given name(dev->name), exists, >> - device probe, doesn't return an error. >> >> The returned device is activated and ready to use. >> >> Note: >> This function returns the first device, which name is equal >> to the given one. This means, that using this function you must >> assume, that the device name is unique in the given uclass's ID >> device list. >> >> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> >> Cc: Simon Glass <sjg@chromium.org> >> --- >> Changes V4: >> - new commit >> --- >> drivers/core/uclass.c | 11 +++++++++++ >> include/dm/uclass.h | 15 +++++++++++++++ >> 2 files changed, 26 insertions(+) > > Acked-by: Simon Glass <sjg@chromium.org> Applied to u-boot-dm, thanks! ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 08/10] dm: core: device: add function: dev_get_driver_ops() 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak ` (6 preceding siblings ...) 2015-04-15 11:07 ` [U-Boot] [PATCH V4 07/10] dm: core: uclass: add function: uclass_get_device_by_name() Przemyslaw Marczak @ 2015-04-15 11:07 ` Przemyslaw Marczak 2015-04-19 13:24 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 09/10] dm: core: device: add function: dev_get_uclass_name() Przemyslaw Marczak ` (2 subsequent siblings) 10 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-15 11:07 UTC (permalink / raw) To: u-boot This commit extends the driver model device's API by function: - dev_get_driver_ops() And this function returns the device's driver's operations if given: - dev pointer, is non-NULL - dev->driver->ops pointer, is non-NULL in other case the, the NULL pointer is returned. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V4: - new commit --- drivers/core/device.c | 8 ++++++++ include/dm/device.h | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/core/device.c b/drivers/core/device.c index 80eb55b..d024abb 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -499,6 +499,14 @@ ulong dev_get_driver_data(struct udevice *dev) return dev->driver_data; } +const void *dev_get_driver_ops(struct udevice *dev) +{ + if (!dev || !dev->driver->ops) + return NULL; + + return dev->driver->ops; +} + enum uclass_id device_get_uclass_id(struct udevice *dev) { return dev->uclass->uc_drv->id; diff --git a/include/dm/device.h b/include/dm/device.h index ad002fe..049cb2f 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -280,6 +280,17 @@ void *dev_get_uclass_priv(struct udevice *dev); */ ulong dev_get_driver_data(struct udevice *dev); +/** + * dev_get_driver_ops() - get the device's driver's operations + * + * This checks that dev is not NULL, and returns the pointer to device's + * driver's operations. + * + * @dev: Device to check + * @return void pointer to driver's operations or NULL for NULL-dev or NULL-ops + */ +const void *dev_get_driver_ops(struct udevice *dev); + /* * device_get_uclass_id() - return the uclass ID of a device * -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 08/10] dm: core: device: add function: dev_get_driver_ops() 2015-04-15 11:07 ` [U-Boot] [PATCH V4 08/10] dm: core: device: add function: dev_get_driver_ops() Przemyslaw Marczak @ 2015-04-19 13:24 ` Simon Glass 2015-04-20 3:23 ` Simon Glass 0 siblings, 1 reply; 61+ messages in thread From: Simon Glass @ 2015-04-19 13:24 UTC (permalink / raw) To: u-boot Hi Przemyslaw, On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit extends the driver model device's API by function: > - dev_get_driver_ops() > > And this function returns the device's driver's operations if given: > - dev pointer, is non-NULL > - dev->driver->ops pointer, is non-NULL > in other case the, the NULL pointer is returned. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > Changes V4: > - new commit > --- > drivers/core/device.c | 8 ++++++++ > include/dm/device.h | 11 +++++++++++ > 2 files changed, 19 insertions(+) > > diff --git a/drivers/core/device.c b/drivers/core/device.c > index 80eb55b..d024abb 100644 > --- a/drivers/core/device.c > +++ b/drivers/core/device.c > @@ -499,6 +499,14 @@ ulong dev_get_driver_data(struct udevice *dev) > return dev->driver_data; > } > > +const void *dev_get_driver_ops(struct udevice *dev) > +{ > + if (!dev || !dev->driver->ops) The second condition seems redundant to me. Perhaps it will become an assert or other check one day. Anyway: Acked-by: Simon Glass <sjg@chromium.org> > + return NULL; > + > + return dev->driver->ops; > +} > + > enum uclass_id device_get_uclass_id(struct udevice *dev) > { > return dev->uclass->uc_drv->id; > diff --git a/include/dm/device.h b/include/dm/device.h > index ad002fe..049cb2f 100644 > --- a/include/dm/device.h > +++ b/include/dm/device.h > @@ -280,6 +280,17 @@ void *dev_get_uclass_priv(struct udevice *dev); > */ > ulong dev_get_driver_data(struct udevice *dev); > > +/** > + * dev_get_driver_ops() - get the device's driver's operations > + * > + * This checks that dev is not NULL, and returns the pointer to device's > + * driver's operations. > + * > + * @dev: Device to check > + * @return void pointer to driver's operations or NULL for NULL-dev or NULL-ops > + */ > +const void *dev_get_driver_ops(struct udevice *dev); > + > /* > * device_get_uclass_id() - return the uclass ID of a device > * > -- > 1.9.1 > Regards, Simon ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 08/10] dm: core: device: add function: dev_get_driver_ops() 2015-04-19 13:24 ` Simon Glass @ 2015-04-20 3:23 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-20 3:23 UTC (permalink / raw) To: u-boot On 19 April 2015 at 07:24, Simon Glass <sjg@chromium.org> wrote: > Hi Przemyslaw, > > On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: >> This commit extends the driver model device's API by function: >> - dev_get_driver_ops() >> >> And this function returns the device's driver's operations if given: >> - dev pointer, is non-NULL >> - dev->driver->ops pointer, is non-NULL >> in other case the, the NULL pointer is returned. >> >> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> >> Cc: Simon Glass <sjg@chromium.org> >> --- >> Changes V4: >> - new commit >> --- >> drivers/core/device.c | 8 ++++++++ >> include/dm/device.h | 11 +++++++++++ >> 2 files changed, 19 insertions(+) >> >> diff --git a/drivers/core/device.c b/drivers/core/device.c >> index 80eb55b..d024abb 100644 >> --- a/drivers/core/device.c >> +++ b/drivers/core/device.c >> @@ -499,6 +499,14 @@ ulong dev_get_driver_data(struct udevice *dev) >> return dev->driver_data; >> } >> >> +const void *dev_get_driver_ops(struct udevice *dev) >> +{ >> + if (!dev || !dev->driver->ops) > > The second condition seems redundant to me. Perhaps it will become an > assert or other check one day. Anyway: > > Acked-by: Simon Glass <sjg@chromium.org> Applied to u-boot-dm, thanks! ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 09/10] dm: core: device: add function: dev_get_uclass_name() 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak ` (7 preceding siblings ...) 2015-04-15 11:07 ` [U-Boot] [PATCH V4 08/10] dm: core: device: add function: dev_get_driver_ops() Przemyslaw Marczak @ 2015-04-15 11:07 ` Przemyslaw Marczak 2015-04-19 13:24 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 10/10] dm: test: Add tests for get/find uclass's device by name Przemyslaw Marczak 2015-04-20 3:22 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Simon Glass 10 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-15 11:07 UTC (permalink / raw) To: u-boot This commit extends the driver model device's API by function: - dev_get_uclass_name() And this function returns the device's uclass driver name if: - given dev pointer, is non_NULL otherwise, the NULL pointer is returned. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V4: - new commit --- drivers/core/device.c | 8 ++++++++ include/dm/device.h | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/drivers/core/device.c b/drivers/core/device.c index d024abb..df81b8e 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -512,6 +512,14 @@ enum uclass_id device_get_uclass_id(struct udevice *dev) return dev->uclass->uc_drv->id; } +const char *dev_get_uclass_name(struct udevice *dev) +{ + if (!dev) + return NULL; + + return dev->uclass->uc_drv->name; +} + #ifdef CONFIG_OF_CONTROL fdt_addr_t dev_get_addr(struct udevice *dev) { diff --git a/include/dm/device.h b/include/dm/device.h index 049cb2f..18296bb 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -299,6 +299,16 @@ const void *dev_get_driver_ops(struct udevice *dev); */ enum uclass_id device_get_uclass_id(struct udevice *dev); +/* + * dev_get_uclass_name() - return the uclass name of a device + * + * This checks that dev is not NULL. + * + * @dev: Device to check + * @return pointer to the uclass name for the device + */ +const char *dev_get_uclass_name(struct udevice *dev); + /** * device_get_child() - Get the child of a device by index * -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 09/10] dm: core: device: add function: dev_get_uclass_name() 2015-04-15 11:07 ` [U-Boot] [PATCH V4 09/10] dm: core: device: add function: dev_get_uclass_name() Przemyslaw Marczak @ 2015-04-19 13:24 ` Simon Glass 2015-04-20 3:23 ` Simon Glass 0 siblings, 1 reply; 61+ messages in thread From: Simon Glass @ 2015-04-19 13:24 UTC (permalink / raw) To: u-boot On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit extends the driver model device's API by function: > - dev_get_uclass_name() > > And this function returns the device's uclass driver name if: > - given dev pointer, is non_NULL > otherwise, the NULL pointer is returned. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > Changes V4: > - new commit > --- > drivers/core/device.c | 8 ++++++++ > include/dm/device.h | 10 ++++++++++ > 2 files changed, 18 insertions(+) Acked-by: Simon Glass <sjg@chromium.org> ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 09/10] dm: core: device: add function: dev_get_uclass_name() 2015-04-19 13:24 ` Simon Glass @ 2015-04-20 3:23 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-20 3:23 UTC (permalink / raw) To: u-boot On 19 April 2015 at 07:24, Simon Glass <sjg@chromium.org> wrote: > On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: >> This commit extends the driver model device's API by function: >> - dev_get_uclass_name() >> >> And this function returns the device's uclass driver name if: >> - given dev pointer, is non_NULL >> otherwise, the NULL pointer is returned. >> >> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> >> Cc: Simon Glass <sjg@chromium.org> >> --- >> Changes V4: >> - new commit >> --- >> drivers/core/device.c | 8 ++++++++ >> include/dm/device.h | 10 ++++++++++ >> 2 files changed, 18 insertions(+) > > Acked-by: Simon Glass <sjg@chromium.org> Applied to u-boot-dm, thanks! ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 10/10] dm: test: Add tests for get/find uclass's device by name 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak ` (8 preceding siblings ...) 2015-04-15 11:07 ` [U-Boot] [PATCH V4 09/10] dm: core: device: add function: dev_get_uclass_name() Przemyslaw Marczak @ 2015-04-15 11:07 ` Przemyslaw Marczak 2015-04-19 13:25 ` Simon Glass 2015-04-20 3:22 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Simon Glass 10 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-15 11:07 UTC (permalink / raw) To: u-boot This commit introduces simple tests for functions: - uclass_find_device_by_name() - uclass_get_device_by_name() Tests added by this commit: - Test: dm_test_uclass_devices_find_by_name: for uclass id: UCLASS_TEST_FDT * get uclass's devices by uclass_find_first/next_device() each as 'testdev', * for each returned device, call: uclass_find_device_by_name(), with previously returned device's name as an argument ('testdev->name'). * for the found device ('founddev') check if: * founddev != NULL * testdev == founddev * testdev->name == founddev->name (by strcmp) - Test: dm_test_uclass_devices_get_by_name: for uclass id: UCLASS_TEST_FDT * get uclass's devices by uclass_get_first/next_device() each as 'testdev', * for each returned device, call: uclass_get_device_by_name(), with previously returned device's name as an argument ('testdev->name'). * for the found device ('founddev') check if: * founddev != NULL * founddev is active * testdev == founddev * testdev->name == founddev->name (by strcmp) Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V4: -new commit --- test/dm/core.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/test/dm/core.c b/test/dm/core.c index 3a8dd1d..b678511 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -674,6 +674,43 @@ static int dm_test_uclass_devices_find(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA); +static int dm_test_uclass_devices_find_by_name(struct dm_test_state *dms) +{ + struct udevice *founddev; + struct udevice *testdev; + int foundret, ret; + + /** + * For each test device found in fdt like: "a-test", "b-test", etc., + * use its name and try to find it by uclass_find_device_by_name(). + * Then, on success check if: + * - current 'testdev' name is equal to the returned 'founddev' name + * - current 'testdev' pointer is equal to the returned 'founddev' + * + * We assume that, each uclass's device name is unique, so if not, then + * this will fail on checking condition: testdev == founddev, since the + * uclass_find_device_by_name(), returns the first device by given name. + */ + for (ret = uclass_find_first_device(UCLASS_TEST_FDT, &testdev); + testdev; + ret = uclass_find_next_device(&testdev)) { + ut_assert(!ret); + ut_assert(testdev); + + foundret = uclass_find_device_by_name(UCLASS_TEST_FDT, + testdev->name, + &founddev); + + ut_assert(!foundret); + ut_assert(testdev); + ut_asserteq_str(testdev->name, founddev->name); + ut_asserteq_ptr(testdev, founddev); + } + + return 0; +} +DM_TEST(dm_test_uclass_devices_find_by_name, DM_TESTF_SCAN_FDT); + static int dm_test_uclass_devices_get(struct dm_test_state *dms) { struct udevice *dev; @@ -691,6 +728,50 @@ static int dm_test_uclass_devices_get(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA); +static int dm_test_uclass_devices_get_by_name(struct dm_test_state *dms) +{ + struct udevice *founddev; + struct udevice *testdev; + int ret, foundret; + + /** + * For each test device found in fdt like: "a-test", "b-test", etc., + * use its name and try to get it by uclass_get_device_by_name(). + * On success check if: + * - returned founddev' is active + * - current 'testdev' name is equal to the returned 'founddev' name + * - current 'testdev' pointer is equal to the returned 'founddev' + * + * We asserts that the 'testdev' is active on each loop entry, so we + * could be sure that the 'founddev' is activated too, but for sure + * we check it again. + * + * We assume that, each uclass's device name is unique, so if not, then + * this will fail on checking condition: testdev == founddev, since the + * uclass_get_device_by_name(), returns the first device by given name. + */ + for (ret = uclass_first_device(UCLASS_TEST_FDT, &testdev); + testdev; + ret = uclass_next_device(&testdev)) { + ut_assert(!ret); + ut_assert(testdev); + ut_assert(device_active(testdev)); + + foundret = uclass_get_device_by_name(UCLASS_TEST_FDT, + testdev->name, + &founddev); + + ut_assert(!foundret); + ut_assert(founddev); + ut_assert(device_active(founddev)); + ut_asserteq_str(testdev->name, founddev->name); + ut_asserteq_ptr(testdev, founddev); + } + + return 0; +} +DM_TEST(dm_test_uclass_devices_get_by_name, DM_TESTF_SCAN_FDT); + static int dm_test_device_get_uclass_id(struct dm_test_state *dms) { struct udevice *dev; -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 10/10] dm: test: Add tests for get/find uclass's device by name 2015-04-15 11:07 ` [U-Boot] [PATCH V4 10/10] dm: test: Add tests for get/find uclass's device by name Przemyslaw Marczak @ 2015-04-19 13:25 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-19 13:25 UTC (permalink / raw) To: u-boot Hi Przemyslaw, On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit introduces simple tests for functions: > - uclass_find_device_by_name() > - uclass_get_device_by_name() > > Tests added by this commit: > - Test: dm_test_uclass_devices_find_by_name: for uclass id: UCLASS_TEST_FDT > * get uclass's devices by uclass_find_first/next_device() each as 'testdev', > * for each returned device, call: uclass_find_device_by_name(), > with previously returned device's name as an argument ('testdev->name'). > * for the found device ('founddev') check if: > * founddev != NULL > * testdev == founddev > * testdev->name == founddev->name (by strcmp) > > - Test: dm_test_uclass_devices_get_by_name: for uclass id: UCLASS_TEST_FDT > * get uclass's devices by uclass_get_first/next_device() each as 'testdev', > * for each returned device, call: uclass_get_device_by_name(), > with previously returned device's name as an argument ('testdev->name'). > * for the found device ('founddev') check if: > * founddev != NULL > * founddev is active > * testdev == founddev > * testdev->name == founddev->name (by strcmp) > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > Changes V4: > -new commit > --- > test/dm/core.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 81 insertions(+) > > diff --git a/test/dm/core.c b/test/dm/core.c > index 3a8dd1d..b678511 100644 > --- a/test/dm/core.c > +++ b/test/dm/core.c > @@ -674,6 +674,43 @@ static int dm_test_uclass_devices_find(struct dm_test_state *dms) > } > DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA); > > +static int dm_test_uclass_devices_find_by_name(struct dm_test_state *dms) > +{ > + struct udevice *founddev; > + struct udevice *testdev; > + int foundret, ret; > + > + /** /* (It is not a docbook comment for a function, etc.) > + * For each test device found in fdt like: "a-test", "b-test", etc., > + * use its name and try to find it by uclass_find_device_by_name(). > + * Then, on success check if: > + * - current 'testdev' name is equal to the returned 'founddev' name > + * - current 'testdev' pointer is equal to the returned 'founddev' > + * > + * We assume that, each uclass's device name is unique, so if not, then > + * this will fail on checking condition: testdev == founddev, since the > + * uclass_find_device_by_name(), returns the first device by given name. > + */ > + for (ret = uclass_find_first_device(UCLASS_TEST_FDT, &testdev); > + testdev; > + ret = uclass_find_next_device(&testdev)) { > + ut_assert(!ret); > + ut_assert(testdev); > + > + foundret = uclass_find_device_by_name(UCLASS_TEST_FDT, > + testdev->name, > + &founddev); > + > + ut_assert(!foundret); > + ut_assert(testdev); > + ut_asserteq_str(testdev->name, founddev->name); > + ut_asserteq_ptr(testdev, founddev); > + } > + > + return 0; > +} > +DM_TEST(dm_test_uclass_devices_find_by_name, DM_TESTF_SCAN_FDT); > + > static int dm_test_uclass_devices_get(struct dm_test_state *dms) > { > struct udevice *dev; > @@ -691,6 +728,50 @@ static int dm_test_uclass_devices_get(struct dm_test_state *dms) > } > DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA); > > +static int dm_test_uclass_devices_get_by_name(struct dm_test_state *dms) > +{ > + struct udevice *founddev; > + struct udevice *testdev; > + int ret, foundret; > + > + /** /* > + * For each test device found in fdt like: "a-test", "b-test", etc., > + * use its name and try to get it by uclass_get_device_by_name(). > + * On success check if: > + * - returned founddev' is active > + * - current 'testdev' name is equal to the returned 'founddev' name > + * - current 'testdev' pointer is equal to the returned 'founddev' > + * > + * We asserts that the 'testdev' is active on each loop entry, so we > + * could be sure that the 'founddev' is activated too, but for sure > + * we check it again. > + * > + * We assume that, each uclass's device name is unique, so if not, then > + * this will fail on checking condition: testdev == founddev, since the > + * uclass_get_device_by_name(), returns the first device by given name. > + */ > + for (ret = uclass_first_device(UCLASS_TEST_FDT, &testdev); > + testdev; > + ret = uclass_next_device(&testdev)) { > + ut_assert(!ret); > + ut_assert(testdev); > + ut_assert(device_active(testdev)); > + > + foundret = uclass_get_device_by_name(UCLASS_TEST_FDT, > + testdev->name, > + &founddev); > + > + ut_assert(!foundret); nit: ut_assertok(foundret); > + ut_assert(founddev); > + ut_assert(device_active(founddev)); > + ut_asserteq_str(testdev->name, founddev->name); > + ut_asserteq_ptr(testdev, founddev); > + } > + > + return 0; > +} > +DM_TEST(dm_test_uclass_devices_get_by_name, DM_TESTF_SCAN_FDT); > + > static int dm_test_device_get_uclass_id(struct dm_test_state *dms) > { > struct udevice *dev; > -- > 1.9.1 > If you like I can tweak these when applying. I need to wait until the driver model pull request is accepted before applying anything else. Regards, Simon ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak ` (9 preceding siblings ...) 2015-04-15 11:07 ` [U-Boot] [PATCH V4 10/10] dm: test: Add tests for get/find uclass's device by name Przemyslaw Marczak @ 2015-04-20 3:22 ` Simon Glass 2015-04-20 10:55 ` Przemyslaw Marczak 2015-04-20 11:32 ` [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak 10 siblings, 2 replies; 61+ messages in thread From: Simon Glass @ 2015-04-20 3:22 UTC (permalink / raw) To: u-boot Hi Przemyslaw, On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > Hello, > Before merge, I would like to extend this patchset by additional functions [V4], > which are now the base for my work on PMIC. > > The base version: > > The struct udevice provides two fields for device's platform data: > - .platdata - to keep platform-dependent data for the device driver > - .parent_platdata - to keep platform-dependent data for the device parent > > Some implementations may need addidional platform data, which could be owned > by the uclass. For example, the regulator device's constraints. > > This patchset adds the additional field: > - .uclass_platdata - to keep platform-dependend data for the uclass driver > > Two tests are added to the test framework: > - one for check dev->uclass_platdata pointer > - second for validation the data assigned to by test uclass's post_bind() method > > Change in V2: > - implementation of functions for getting the uclass's device without probe it > - cleanup test code > > Change in V3: > - add tests for uclass device get/find functions > > Change in V4: > - remove type 'static' for uclass_get_device_tail() > - add: class_get/find_device_by_name() with sandbox tests > - add: dev_get_driver_ops() > - add: dev_get_uclass_name() The driver model tree has gone to mainline now so I'm going to pick this series up. I'm leaving out patches 5 and 10 for now as I have responded with minor nits. Can you please respin against u-boot-dm/master? Thanks, Simon ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests 2015-04-20 3:22 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Simon Glass @ 2015-04-20 10:55 ` Przemyslaw Marczak 2015-04-20 11:32 ` [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak 1 sibling, 0 replies; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-20 10:55 UTC (permalink / raw) To: u-boot Hello Simon, On 04/20/2015 05:22 AM, Simon Glass wrote: > Hi Przemyslaw, > > On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak@samsung.com> wrote: >> Hello, >> Before merge, I would like to extend this patchset by additional functions [V4], >> which are now the base for my work on PMIC. >> >> The base version: >> >> The struct udevice provides two fields for device's platform data: >> - .platdata - to keep platform-dependent data for the device driver >> - .parent_platdata - to keep platform-dependent data for the device parent >> >> Some implementations may need addidional platform data, which could be owned >> by the uclass. For example, the regulator device's constraints. >> >> This patchset adds the additional field: >> - .uclass_platdata - to keep platform-dependend data for the uclass driver >> >> Two tests are added to the test framework: >> - one for check dev->uclass_platdata pointer >> - second for validation the data assigned to by test uclass's post_bind() method >> >> Change in V2: >> - implementation of functions for getting the uclass's device without probe it >> - cleanup test code >> >> Change in V3: >> - add tests for uclass device get/find functions >> >> Change in V4: >> - remove type 'static' for uclass_get_device_tail() >> - add: class_get/find_device_by_name() with sandbox tests >> - add: dev_get_driver_ops() >> - add: dev_get_uclass_name() > > The driver model tree has gone to mainline now so I'm going to pick > this series up. > > I'm leaving out patches 5 and 10 for now as I have responded with > minor nits. Can you please respin against u-boot-dm/master? > > Thanks, > Simon > Thank you for taking this, I will resend those two in a moment. Best regards, -- Przemyslaw Marczak Samsung R&D Institute Poland Samsung Electronics p.marczak at samsung.com ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() 2015-04-20 3:22 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Simon Glass 2015-04-20 10:55 ` Przemyslaw Marczak @ 2015-04-20 11:32 ` Przemyslaw Marczak 2015-04-20 11:32 ` [U-Boot] [PATCH V5 2/3] dm: test: Add tests for get/find uclass's device by name Przemyslaw Marczak ` (2 more replies) 1 sibling, 3 replies; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-20 11:32 UTC (permalink / raw) To: u-boot Uclass API provides a few functions for get/find the device. To provide a complete function set of uclass-internal functions, for use by the drivers, the function uclass_get_device_tail() should be non-static. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V4: - new commit Changes V5: - drivers/core/uclass.c - uclass_get_device_tail() - remove function comment --- drivers/core/uclass.c | 12 +----------- include/dm/uclass-internal.h | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index c1ebee7..7627ad1 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -263,17 +263,7 @@ static int uclass_find_device_by_of_offset(enum uclass_id id, int node, return -ENODEV; } -/** - * uclass_get_device_tail() - handle the end of a get_device call - * - * This handles returning an error or probing a device as needed. - * - * @dev: Device that needs to be probed - * @ret: Error to return. If non-zero then the device is not probed - * @devp: Returns the value of 'dev' if there is no error - * @return ret, if non-zero, else the result of the device_probe() call - */ -static int uclass_get_device_tail(struct udevice *dev, int ret, +int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp) { if (ret) diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index d0f1e22..153f2a7 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -11,12 +11,25 @@ #define _DM_UCLASS_INTERNAL_H /** + * uclass_get_device_tail() - handle the end of a get_device call + * + * This handles returning an error or probing a device as needed. + * + * @dev: Device that needs to be probed + * @ret: Error to return. If non-zero then the device is not probed + * @devp: Returns the value of 'dev' if there is no error + * @return ret, if non-zero, else the result of the device_probe() call + */ +int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp); + +/** * uclass_find_device() - Return n-th child of uclass * @id: Id number of the uclass * @index: Position of the child in uclass's list * #devp: Returns pointer to device, or NULL on error * - * The device is not prepared for use - this is an internal function + * The device is not prepared for use - this is an internal function. + * The function uclass_get_device_tail() can be used to probe the device. * * @return the uclass pointer of a child at the given index or * return NULL on error. @@ -28,7 +41,8 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp); * @id: Id number of the uclass * #devp: Returns pointer to device, or NULL on error * - * The device is not prepared for use - this is an internal function + * The device is not prepared for use - this is an internal function. + * The function uclass_get_device_tail() can be used to probe the device. * * @return 0 if OK (found or not found), -1 on error */ @@ -39,7 +53,8 @@ int uclass_find_first_device(enum uclass_id id, struct udevice **devp); * @devp: On entry, pointer to device to lookup. On exit, returns pointer * to the next device in the same uclass, or NULL if none * - * The device is not prepared for use - this is an internal function + * The device is not prepared for use - this is an internal function. + * The function uclass_get_device_tail() can be used to probe the device. * * @return 0 if OK (found or not found), -1 on error */ -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V5 2/3] dm: test: Add tests for get/find uclass's device by name 2015-04-20 11:32 ` [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak @ 2015-04-20 11:32 ` Przemyslaw Marczak 2015-04-20 21:24 ` Simon Glass 2015-04-20 11:32 ` [U-Boot] [PATCH V5 3/3] dm: core: precise comments for get/find " Przemyslaw Marczak 2015-04-20 21:24 ` [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() Simon Glass 2 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-20 11:32 UTC (permalink / raw) To: u-boot This commit introduces simple tests for functions: - uclass_find_device_by_name() - uclass_get_device_by_name() Tests added by this commit: - Test: dm_test_uclass_devices_find_by_name: for uclass id: UCLASS_TEST_FDT * get uclass's devices by uclass_find_first/next_device() each as 'testdev', * for each returned device, call: uclass_find_device_by_name(), with previously returned device's name as an argument ('testdev->name'). * for the found device ('founddev') check if: * founddev != NULL * testdev == founddev * testdev->name == founddev->name (by strcmp) - Test: dm_test_uclass_devices_get_by_name: for uclass id: UCLASS_TEST_FDT * get uclass's devices by uclass_get_first/next_device() each as 'testdev', * for each returned device, call: uclass_get_device_by_name(), with previously returned device's name as an argument ('testdev->name'). * for the found device ('founddev') check if: * founddev != NULL * founddev is active * testdev == founddev * testdev->name == founddev->name (by strcmp) Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Changes V4: -new commit Changes V5: - code cleanup --- test/dm/core.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/test/dm/core.c b/test/dm/core.c index 3a8dd1d..7f7b977 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -674,6 +674,43 @@ static int dm_test_uclass_devices_find(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA); +static int dm_test_uclass_devices_find_by_name(struct dm_test_state *dms) +{ + struct udevice *finddev; + struct udevice *testdev; + int findret, ret; + + /* + * For each test device found in fdt like: "a-test", "b-test", etc., + * use its name and try to find it by uclass_find_device_by_name(). + * Then, on success check if: + * - current 'testdev' name is equal to the returned 'finddev' name + * - current 'testdev' pointer is equal to the returned 'finddev' + * + * We assume that, each uclass's device name is unique, so if not, then + * this will fail on checking condition: testdev == finddev, since the + * uclass_find_device_by_name(), returns the first device by given name. + */ + for (ret = uclass_find_first_device(UCLASS_TEST_FDT, &testdev); + testdev; + ret = uclass_find_next_device(&testdev)) { + ut_assertok(ret); + ut_assert(testdev); + + findret = uclass_find_device_by_name(UCLASS_TEST_FDT, + testdev->name, + &finddev); + + ut_assertok(findret); + ut_assert(testdev); + ut_asserteq_str(testdev->name, finddev->name); + ut_asserteq_ptr(testdev, finddev); + } + + return 0; +} +DM_TEST(dm_test_uclass_devices_find_by_name, DM_TESTF_SCAN_FDT); + static int dm_test_uclass_devices_get(struct dm_test_state *dms) { struct udevice *dev; @@ -691,6 +728,50 @@ static int dm_test_uclass_devices_get(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA); +static int dm_test_uclass_devices_get_by_name(struct dm_test_state *dms) +{ + struct udevice *finddev; + struct udevice *testdev; + int ret, findret; + + /* + * For each test device found in fdt like: "a-test", "b-test", etc., + * use its name and try to get it by uclass_get_device_by_name(). + * On success check if: + * - returned finddev' is active + * - current 'testdev' name is equal to the returned 'finddev' name + * - current 'testdev' pointer is equal to the returned 'finddev' + * + * We asserts that the 'testdev' is active on each loop entry, so we + * could be sure that the 'finddev' is activated too, but for sure + * we check it again. + * + * We assume that, each uclass's device name is unique, so if not, then + * this will fail on checking condition: testdev == finddev, since the + * uclass_get_device_by_name(), returns the first device by given name. + */ + for (ret = uclass_first_device(UCLASS_TEST_FDT, &testdev); + testdev; + ret = uclass_next_device(&testdev)) { + ut_assertok(ret); + ut_assert(testdev); + ut_assert(device_active(testdev)); + + findret = uclass_get_device_by_name(UCLASS_TEST_FDT, + testdev->name, + &finddev); + + ut_assertok(findret); + ut_assert(finddev); + ut_assert(device_active(finddev)); + ut_asserteq_str(testdev->name, finddev->name); + ut_asserteq_ptr(testdev, finddev); + } + + return 0; +} +DM_TEST(dm_test_uclass_devices_get_by_name, DM_TESTF_SCAN_FDT); + static int dm_test_device_get_uclass_id(struct dm_test_state *dms) { struct udevice *dev; -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V5 2/3] dm: test: Add tests for get/find uclass's device by name 2015-04-20 11:32 ` [U-Boot] [PATCH V5 2/3] dm: test: Add tests for get/find uclass's device by name Przemyslaw Marczak @ 2015-04-20 21:24 ` Simon Glass 2015-04-22 16:52 ` Simon Glass 0 siblings, 1 reply; 61+ messages in thread From: Simon Glass @ 2015-04-20 21:24 UTC (permalink / raw) To: u-boot On 20 April 2015 at 05:32, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > This commit introduces simple tests for functions: > - uclass_find_device_by_name() > - uclass_get_device_by_name() > > Tests added by this commit: > - Test: dm_test_uclass_devices_find_by_name: for uclass id: UCLASS_TEST_FDT > * get uclass's devices by uclass_find_first/next_device() each as 'testdev', > * for each returned device, call: uclass_find_device_by_name(), > with previously returned device's name as an argument ('testdev->name'). > * for the found device ('founddev') check if: > * founddev != NULL > * testdev == founddev > * testdev->name == founddev->name (by strcmp) > > - Test: dm_test_uclass_devices_get_by_name: for uclass id: UCLASS_TEST_FDT > * get uclass's devices by uclass_get_first/next_device() each as 'testdev', > * for each returned device, call: uclass_get_device_by_name(), > with previously returned device's name as an argument ('testdev->name'). > * for the found device ('founddev') check if: > * founddev != NULL > * founddev is active > * testdev == founddev > * testdev->name == founddev->name (by strcmp) > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > Changes V4: > -new commit > > Changes V5: > - code cleanup > --- > test/dm/core.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 81 insertions(+) Acked-by: Simon Glass <sjg@chromium.org> ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V5 2/3] dm: test: Add tests for get/find uclass's device by name 2015-04-20 21:24 ` Simon Glass @ 2015-04-22 16:52 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-22 16:52 UTC (permalink / raw) To: u-boot On 20 April 2015 at 15:24, Simon Glass <sjg@chromium.org> wrote: > On 20 April 2015 at 05:32, Przemyslaw Marczak <p.marczak@samsung.com> wrote: >> This commit introduces simple tests for functions: >> - uclass_find_device_by_name() >> - uclass_get_device_by_name() >> >> Tests added by this commit: >> - Test: dm_test_uclass_devices_find_by_name: for uclass id: UCLASS_TEST_FDT >> * get uclass's devices by uclass_find_first/next_device() each as 'testdev', >> * for each returned device, call: uclass_find_device_by_name(), >> with previously returned device's name as an argument ('testdev->name'). >> * for the found device ('founddev') check if: >> * founddev != NULL >> * testdev == founddev >> * testdev->name == founddev->name (by strcmp) >> >> - Test: dm_test_uclass_devices_get_by_name: for uclass id: UCLASS_TEST_FDT >> * get uclass's devices by uclass_get_first/next_device() each as 'testdev', >> * for each returned device, call: uclass_get_device_by_name(), >> with previously returned device's name as an argument ('testdev->name'). >> * for the found device ('founddev') check if: >> * founddev != NULL >> * founddev is active >> * testdev == founddev >> * testdev->name == founddev->name (by strcmp) >> >> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> >> Cc: Simon Glass <sjg@chromium.org> >> --- >> Changes V4: >> -new commit >> >> Changes V5: >> - code cleanup >> --- >> test/dm/core.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 81 insertions(+) > > Acked-by: Simon Glass <sjg@chromium.org> Applied to u-boot-dm, thanks! ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V5 3/3] dm: core: precise comments for get/find device by name 2015-04-20 11:32 ` [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak 2015-04-20 11:32 ` [U-Boot] [PATCH V5 2/3] dm: test: Add tests for get/find uclass's device by name Przemyslaw Marczak @ 2015-04-20 11:32 ` Przemyslaw Marczak 2015-04-20 21:24 ` Simon Glass 2015-04-20 21:24 ` [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() Simon Glass 2 siblings, 1 reply; 61+ messages in thread From: Przemyslaw Marczak @ 2015-04-20 11:32 UTC (permalink / raw) To: u-boot The functions: - uclass_find_device_by_name() - uclass_get_device_by_name() searches the required device for the exactly given name. This patch, presice this fact for both function's comments. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> --- Canges V5: -new patch --- include/dm/uclass-internal.h | 2 +- include/dm/uclass.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index 153f2a7..a9b2fbe 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -63,7 +63,7 @@ int uclass_find_next_device(struct udevice **devp); /** * uclass_find_device_by_name() - Find uclass device based on ID and name * - * This searches for a device with the given name. + * This searches for a device with the exactly given name. * * The device is NOT probed, it is merely returned. * diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 66e0ea5..4cfc0df 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -132,7 +132,7 @@ int uclass_get_device(enum uclass_id id, int index, struct udevice **devp); /** * uclass_get_device_by_name() - Get a uclass device by it's name * - * This searches the devices in the uclass for one with the given name. + * This searches the devices in the uclass for one with the exactly given name. * * The device is probed to activate it ready for use. * -- 1.9.1 ^ permalink raw reply related [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V5 3/3] dm: core: precise comments for get/find device by name 2015-04-20 11:32 ` [U-Boot] [PATCH V5 3/3] dm: core: precise comments for get/find " Przemyslaw Marczak @ 2015-04-20 21:24 ` Simon Glass 2015-04-22 16:52 ` Simon Glass 0 siblings, 1 reply; 61+ messages in thread From: Simon Glass @ 2015-04-20 21:24 UTC (permalink / raw) To: u-boot On 20 April 2015 at 05:32, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > The functions: > - uclass_find_device_by_name() > - uclass_get_device_by_name() > searches the required device for the exactly given name. > This patch, presice this fact for both function's comments. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > Canges V5: > -new patch > --- > include/dm/uclass-internal.h | 2 +- > include/dm/uclass.h | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) Acked-by: Simon Glass <sjg@chromium.org> ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V5 3/3] dm: core: precise comments for get/find device by name 2015-04-20 21:24 ` Simon Glass @ 2015-04-22 16:52 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-22 16:52 UTC (permalink / raw) To: u-boot On 20 April 2015 at 15:24, Simon Glass <sjg@chromium.org> wrote: > On 20 April 2015 at 05:32, Przemyslaw Marczak <p.marczak@samsung.com> wrote: >> The functions: >> - uclass_find_device_by_name() >> - uclass_get_device_by_name() >> searches the required device for the exactly given name. >> This patch, presice this fact for both function's comments. >> >> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> >> Cc: Simon Glass <sjg@chromium.org> >> --- >> Canges V5: >> -new patch >> --- >> include/dm/uclass-internal.h | 2 +- >> include/dm/uclass.h | 2 +- >> 2 files changed, 2 insertions(+), 2 deletions(-) > > Acked-by: Simon Glass <sjg@chromium.org> Applied to u-boot-dm, thanks! ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() 2015-04-20 11:32 ` [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak 2015-04-20 11:32 ` [U-Boot] [PATCH V5 2/3] dm: test: Add tests for get/find uclass's device by name Przemyslaw Marczak 2015-04-20 11:32 ` [U-Boot] [PATCH V5 3/3] dm: core: precise comments for get/find " Przemyslaw Marczak @ 2015-04-20 21:24 ` Simon Glass 2015-04-22 16:52 ` Simon Glass 2 siblings, 1 reply; 61+ messages in thread From: Simon Glass @ 2015-04-20 21:24 UTC (permalink / raw) To: u-boot On 20 April 2015 at 05:32, Przemyslaw Marczak <p.marczak@samsung.com> wrote: > > Uclass API provides a few functions for get/find the device. > To provide a complete function set of uclass-internal functions, > for use by the drivers, the function uclass_get_device_tail() > should be non-static. > > Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> > Cc: Simon Glass <sjg@chromium.org> > --- > Changes V4: > - new commit > > Changes V5: > - drivers/core/uclass.c - uclass_get_device_tail() - remove function comment > --- > drivers/core/uclass.c | 12 +----------- > include/dm/uclass-internal.h | 21 ++++++++++++++++++--- > 2 files changed, 19 insertions(+), 14 deletions(-) Acked-by: Simon Glass <sjg@chromium.org> ^ permalink raw reply [flat|nested] 61+ messages in thread
* [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() 2015-04-20 21:24 ` [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() Simon Glass @ 2015-04-22 16:52 ` Simon Glass 0 siblings, 0 replies; 61+ messages in thread From: Simon Glass @ 2015-04-22 16:52 UTC (permalink / raw) To: u-boot On 20 April 2015 at 15:24, Simon Glass <sjg@chromium.org> wrote: > On 20 April 2015 at 05:32, Przemyslaw Marczak <p.marczak@samsung.com> wrote: >> >> Uclass API provides a few functions for get/find the device. >> To provide a complete function set of uclass-internal functions, >> for use by the drivers, the function uclass_get_device_tail() >> should be non-static. >> >> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> >> Cc: Simon Glass <sjg@chromium.org> >> --- >> Changes V4: >> - new commit >> >> Changes V5: >> - drivers/core/uclass.c - uclass_get_device_tail() - remove function comment >> --- >> drivers/core/uclass.c | 12 +----------- >> include/dm/uclass-internal.h | 21 ++++++++++++++++++--- >> 2 files changed, 19 insertions(+), 14 deletions(-) > > Acked-by: Simon Glass <sjg@chromium.org> Applied to u-boot-dm, thanks! ^ permalink raw reply [flat|nested] 61+ messages in thread
end of thread, other threads:[~2015-04-22 16:52 UTC | newest] Thread overview: 61+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-04-08 13:01 [U-Boot] [PATCH 0/2] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 2015-04-08 13:01 ` [U-Boot] [PATCH 1/2] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak 2015-04-08 13:47 ` Simon Glass 2015-04-08 13:56 ` Przemyslaw Marczak 2015-04-08 13:01 ` [U-Boot] [PATCH 2/2] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak 2015-04-08 13:47 ` Simon Glass 2015-04-08 13:58 ` Przemyslaw Marczak 2015-04-08 15:32 ` [U-Boot] [PATCH V2 0/3] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 2015-04-08 15:32 ` [U-Boot] [PATCH V2 1/3] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak 2015-04-08 15:39 ` Simon Glass 2015-04-08 15:47 ` Przemyslaw Marczak 2015-04-08 15:32 ` [U-Boot] [PATCH V2 2/3] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak 2015-04-08 15:32 ` [U-Boot] [PATCH V2 3/3] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak 2015-04-08 17:06 ` [U-Boot] [PATCH V3 0/4] dm: core: add device's uclass platform data and tests Przemyslaw Marczak 2015-04-08 17:06 ` [U-Boot] [PATCH V3 1/4] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak 2015-04-09 1:47 ` Simon Glass 2015-04-08 17:06 ` [U-Boot] [PATCH V3 2/4] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak 2015-04-09 1:47 ` Simon Glass 2015-04-08 17:06 ` [U-Boot] [PATCH V3 3/4] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak 2015-04-09 1:47 ` Simon Glass 2015-04-08 17:06 ` [U-Boot] [PATCH V3 4/4] dm: test: Add tests for get/find uclass devices Przemyslaw Marczak 2015-04-09 1:47 ` Simon Glass 2015-04-09 6:54 ` Przemyslaw Marczak 2015-04-09 12:11 ` [U-Boot] [PATCH] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak 2015-04-09 12:16 ` Przemyslaw Marczak 2015-04-15 11:07 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Przemyslaw Marczak 2015-04-15 11:07 ` [U-Boot] [PATCH V4 01/10] dm: core: add internal functions for getting the device without probe Przemyslaw Marczak 2015-04-20 3:22 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 02/10] dm: core: Extend struct udevice by '.uclass_platdata' field Przemyslaw Marczak 2015-04-20 3:22 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 03/10] dm: test: Add tests for device's uclass platform data Przemyslaw Marczak 2015-04-20 3:22 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 04/10] dm: test: Add tests for get/find uclass devices Przemyslaw Marczak 2015-04-20 3:22 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 05/10] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak 2015-04-20 2:03 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 06/10] dm: core: uclass: add function: uclass_find_device_by_name() Przemyslaw Marczak 2015-04-19 13:23 ` Simon Glass 2015-04-20 3:22 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 07/10] dm: core: uclass: add function: uclass_get_device_by_name() Przemyslaw Marczak 2015-04-19 13:23 ` Simon Glass 2015-04-20 3:22 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 08/10] dm: core: device: add function: dev_get_driver_ops() Przemyslaw Marczak 2015-04-19 13:24 ` Simon Glass 2015-04-20 3:23 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 09/10] dm: core: device: add function: dev_get_uclass_name() Przemyslaw Marczak 2015-04-19 13:24 ` Simon Glass 2015-04-20 3:23 ` Simon Glass 2015-04-15 11:07 ` [U-Boot] [PATCH V4 10/10] dm: test: Add tests for get/find uclass's device by name Przemyslaw Marczak 2015-04-19 13:25 ` Simon Glass 2015-04-20 3:22 ` [U-Boot] [PATCH V4 00/10] dm: core: extend API by useful functions with tests Simon Glass 2015-04-20 10:55 ` Przemyslaw Marczak 2015-04-20 11:32 ` [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() Przemyslaw Marczak 2015-04-20 11:32 ` [U-Boot] [PATCH V5 2/3] dm: test: Add tests for get/find uclass's device by name Przemyslaw Marczak 2015-04-20 21:24 ` Simon Glass 2015-04-22 16:52 ` Simon Glass 2015-04-20 11:32 ` [U-Boot] [PATCH V5 3/3] dm: core: precise comments for get/find " Przemyslaw Marczak 2015-04-20 21:24 ` Simon Glass 2015-04-22 16:52 ` Simon Glass 2015-04-20 21:24 ` [U-Boot] [PATCH V5 1/3] dm: core: remove type 'static' of function uclass_get_device_tail() Simon Glass 2015-04-22 16:52 ` Simon Glass
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox