[U-Boot] [PATCH v2 02/12] dm: device: add function device_get_first_child_by_uclass_id()
Przemyslaw Marczak
p.marczak at samsung.com
Wed Mar 25 17:08:06 CET 2015
Hello Simon,
On 03/06/2015 03:11 PM, Simon Glass wrote:
> Hi Przemyslaw,
>
> On 3 March 2015 at 09:24, Przemyslaw Marczak <p.marczak at samsung.com> wrote:
>>
>> To implement functionality for devices connected by some external
>> interface, sometimes there is need to implement more then one,
>> and different uclass type drivers.
>>
>> But only one i2c/spi dm chip can exists, per each bus i2c address
>> or spi select. Then, it seems to be useful, to get the child device
>> by uclass type, for the parent with known chip address.
>>
>> So, this change will be useful for the pmic case:
>> |- i2c bus
>> '- pmic i2c chip (parent)
>> '- uclass regulator (child 1)
>> '- uclass charger (child 2)
>>
>> This will allow to get the regulator or charger device if knows only parent
>> i2c/spi address.
>>
>> Signed-off-by: Przemyslaw Marczak <p.marczak at samsung.com>
>> ---
>> Changes V2:
>> - new commit
>> ---
>> drivers/core/device.c | 15 +++++++++++++++
>> include/dm/device.h | 16 ++++++++++++++++
>> 2 files changed, 31 insertions(+)
>>
>> diff --git a/drivers/core/device.c b/drivers/core/device.c
>> index 73c3e07..76b22cf 100644
>> --- a/drivers/core/device.c
>> +++ b/drivers/core/device.c
>> @@ -397,6 +397,21 @@ int device_find_child_by_of_offset(struct udevice *parent, int of_offset,
>> return -ENODEV;
>> }
>>
>> +int device_get_first_child_by_uclass_id(struct udevice *parent, int uclass_id,
>
> Can you please use the enum here instead of int?
>
>>
>> + struct udevice **devp)
>> +{
>> + struct udevice *dev;
>> +
>> + *devp = NULL;
>> +
>> + list_for_each_entry(dev, &parent->child_head, sibling_node) {
>> + if (dev->driver->id == uclass_id)
>> + return device_get_device_tail(dev, 0, devp);
>> + }
>> +
>> + return -ENODEV;
>> +}
>> +
>> int device_get_child_by_of_offset(struct udevice *parent, int seq,
>> struct udevice **devp)
>> {
>> diff --git a/include/dm/device.h b/include/dm/device.h
>> index 7a48eb8..9f0d6ce 100644
>> --- a/include/dm/device.h
>> +++ b/include/dm/device.h
>> @@ -335,6 +335,22 @@ int device_get_child_by_of_offset(struct udevice *parent, int seq,
>> struct udevice **devp);
>>
>> /**
>> + * device_get_first_child_by_uclass_id() - Get the first child device based
>> + * on UCLASS_ID
>> + *
>> + * Locates a child device by its uclass id.
>> + *
>> + * The device is probed to activate it ready for use.
>> + *
>> + * @parent: Parent device
>> + * @uclass_id: child uclass id
>> + * @devp: Returns pointer to device if found, otherwise this is set to NULL
>> + * @return 0 if OK, -ve on error
>> + */
>> +int device_get_first_child_by_uclass_id(struct udevice *parent, int uclass_id,
>> + struct udevice **devp);
>> +
>> +/**
>> * device_find_first_child() - Find the first child of a device
>> *
>> * @parent: Parent device to search
>> --
>> 1.9.1
>>
>
> Regards,
> Simon
>
This function is discarded in the V3.
Best regards,
--
Przemyslaw Marczak
Samsung R&D Institute Poland
Samsung Electronics
p.marczak at samsung.com
More information about the U-Boot
mailing list