diff mbox

[U-Boot,v5,02/11] reset: add reset_count()

Message ID 1496316982-16572-3-git-send-email-patrice.chotard@st.com
State Superseded
Headers show

Commit Message

Patrice CHOTARD June 1, 2017, 11:36 a.m. UTC
From: Patrice Chotard <patrice.chotard@st.com>

Add reset_count() method to be able to get the number
of resets contained into a resets property. This will allow
to allocate the right amount of memory in order to keep resets
reference. These resets reference can be used later on error path
or in .remove callback to release these resets.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---
v5: 	_ replace fdtdec_parse_phandle_with_args() by dev_read_phandle_with_args()
v4:     _ add reset_count() method

 drivers/reset/reset-uclass.c | 13 +++++++++++++
 include/reset.h              | 11 +++++++++++
 2 files changed, 24 insertions(+)

Comments

Simon Glass June 2, 2017, 2:56 a.m. UTC | #1
On 1 June 2017 at 05:36,  <patrice.chotard@st.com> wrote:
> From: Patrice Chotard <patrice.chotard@st.com>
>
> Add reset_count() method to be able to get the number
> of resets contained into a resets property. This will allow
> to allocate the right amount of memory in order to keep resets
> reference. These resets reference can be used later on error path
> or in .remove callback to release these resets.
>
> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
> ---
> v5:     _ replace fdtdec_parse_phandle_with_args() by dev_read_phandle_with_args()
> v4:     _ add reset_count() method
>
>  drivers/reset/reset-uclass.c | 13 +++++++++++++
>  include/reset.h              | 11 +++++++++++
>  2 files changed, 24 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Marek Vasut June 3, 2017, 6:02 a.m. UTC | #2
On 06/01/2017 01:36 PM, patrice.chotard@st.com wrote:
> From: Patrice Chotard <patrice.chotard@st.com>
> 
> Add reset_count() method to be able to get the number
> of resets contained into a resets property. This will allow
> to allocate the right amount of memory in order to keep resets
> reference. These resets reference can be used later on error path
> or in .remove callback to release these resets.
> 
> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
> ---
> v5: 	_ replace fdtdec_parse_phandle_with_args() by dev_read_phandle_with_args()
> v4:     _ add reset_count() method
> 
>  drivers/reset/reset-uclass.c | 13 +++++++++++++
>  include/reset.h              | 11 +++++++++++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
> index 4fd82b9..4b17d4c 100644
> --- a/drivers/reset/reset-uclass.c
> +++ b/drivers/reset/reset-uclass.c
> @@ -97,6 +97,19 @@ int reset_get_by_name(struct udevice *dev, const char *name,
>  	return reset_get_by_index(dev, index, reset_ctl);
>  }
>  
> +int reset_count(struct udevice *dev)
> +{
> +	int count;
> +	struct ofnode_phandle_args args;
> +
> +	for (count = 0; ; count++) {
> +		if (dev_read_phandle_with_args(dev,
> +					       "resets", "#reset-cells", 0,
> +					       count, &args))

Don't we have some generic thing in libfdt to count number of phandle
args ? This looks weird to me ...

> +			return count;
> +	}
> +}
> +
>  int reset_request(struct reset_ctl *reset_ctl)
>  {
>  	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
> diff --git a/include/reset.h b/include/reset.h
> index 4f2e35f..e8e68b6 100644
> --- a/include/reset.h
> +++ b/include/reset.h
> @@ -100,6 +100,17 @@ int reset_get_by_name(struct udevice *dev, const char *name,
>  		      struct reset_ctl *reset_ctl);
>  
>  /**
> + * reset_count - Get reset count contained in the "resets" property.
> + *
> + * This returns the count of reset found into the "resets" property. This
> + * allows to allocate the right amount of memory to keep reset reference.
> + *
> + * @dev:	The client device.
> + * @return number of resets found.
> + */
> +int reset_count(struct udevice *dev);
> +
> +/**
>   * reset_request - Request a reset signal.
>   *
>   * @reset_ctl:	A reset control struct.
>
Patrice CHOTARD June 5, 2017, 9:34 a.m. UTC | #3
Hi Marek

On 06/03/2017 08:02 AM, Marek Vasut wrote:
> On 06/01/2017 01:36 PM, patrice.chotard@st.com wrote:

>> From: Patrice Chotard <patrice.chotard@st.com>

>>

>> Add reset_count() method to be able to get the number

>> of resets contained into a resets property. This will allow

>> to allocate the right amount of memory in order to keep resets

>> reference. These resets reference can be used later on error path

>> or in .remove callback to release these resets.

>>

>> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

>> ---

>> v5: 	_ replace fdtdec_parse_phandle_with_args() by dev_read_phandle_with_args()

>> v4:     _ add reset_count() method

>>

>>   drivers/reset/reset-uclass.c | 13 +++++++++++++

>>   include/reset.h              | 11 +++++++++++

>>   2 files changed, 24 insertions(+)

>>

>> diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c

>> index 4fd82b9..4b17d4c 100644

>> --- a/drivers/reset/reset-uclass.c

>> +++ b/drivers/reset/reset-uclass.c

>> @@ -97,6 +97,19 @@ int reset_get_by_name(struct udevice *dev, const char *name,

>>   	return reset_get_by_index(dev, index, reset_ctl);

>>   }

>>   

>> +int reset_count(struct udevice *dev)

>> +{

>> +	int count;

>> +	struct ofnode_phandle_args args;

>> +

>> +	for (count = 0; ; count++) {

>> +		if (dev_read_phandle_with_args(dev,

>> +					       "resets", "#reset-cells", 0,

>> +					       count, &args))

> 

> Don't we have some generic thing in libfdt to count number of phandle

> args ? This looks weird to me ...


I didn't find anything in libfdt doing that.

Patrice

> 

>> +			return count;

>> +	}

>> +}

>> +

>>   int reset_request(struct reset_ctl *reset_ctl)

>>   {

>>   	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);

>> diff --git a/include/reset.h b/include/reset.h

>> index 4f2e35f..e8e68b6 100644

>> --- a/include/reset.h

>> +++ b/include/reset.h

>> @@ -100,6 +100,17 @@ int reset_get_by_name(struct udevice *dev, const char *name,

>>   		      struct reset_ctl *reset_ctl);

>>   

>>   /**

>> + * reset_count - Get reset count contained in the "resets" property.

>> + *

>> + * This returns the count of reset found into the "resets" property. This

>> + * allows to allocate the right amount of memory to keep reset reference.

>> + *

>> + * @dev:	The client device.

>> + * @return number of resets found.

>> + */

>> +int reset_count(struct udevice *dev);

>> +

>> +/**

>>    * reset_request - Request a reset signal.

>>    *

>>    * @reset_ctl:	A reset control struct.

>>

> 

>
Marek Vasut June 5, 2017, 11:18 a.m. UTC | #4
On 06/05/2017 11:34 AM, Patrice CHOTARD wrote:
> Hi Marek
> 
> On 06/03/2017 08:02 AM, Marek Vasut wrote:
>> On 06/01/2017 01:36 PM, patrice.chotard@st.com wrote:
>>> From: Patrice Chotard <patrice.chotard@st.com>
>>>
>>> Add reset_count() method to be able to get the number
>>> of resets contained into a resets property. This will allow
>>> to allocate the right amount of memory in order to keep resets
>>> reference. These resets reference can be used later on error path
>>> or in .remove callback to release these resets.
>>>
>>> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
>>> ---
>>> v5: 	_ replace fdtdec_parse_phandle_with_args() by dev_read_phandle_with_args()
>>> v4:     _ add reset_count() method
>>>
>>>   drivers/reset/reset-uclass.c | 13 +++++++++++++
>>>   include/reset.h              | 11 +++++++++++
>>>   2 files changed, 24 insertions(+)
>>>
>>> diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
>>> index 4fd82b9..4b17d4c 100644
>>> --- a/drivers/reset/reset-uclass.c
>>> +++ b/drivers/reset/reset-uclass.c
>>> @@ -97,6 +97,19 @@ int reset_get_by_name(struct udevice *dev, const char *name,
>>>   	return reset_get_by_index(dev, index, reset_ctl);
>>>   }
>>>   
>>> +int reset_count(struct udevice *dev)
>>> +{
>>> +	int count;
>>> +	struct ofnode_phandle_args args;
>>> +
>>> +	for (count = 0; ; count++) {
>>> +		if (dev_read_phandle_with_args(dev,
>>> +					       "resets", "#reset-cells", 0,
>>> +					       count, &args))
>>
>> Don't we have some generic thing in libfdt to count number of phandle
>> args ? This looks weird to me ...
> 
> I didn't find anything in libfdt doing that.

Maybe someone else can hop in, I'm quite sure there should be something
like that.
Simon Glass June 6, 2017, 9:08 p.m. UTC | #5
Hi,

On 5 June 2017 at 05:18, Marek Vasut <marex@denx.de> wrote:
> On 06/05/2017 11:34 AM, Patrice CHOTARD wrote:
>> Hi Marek
>>
>> On 06/03/2017 08:02 AM, Marek Vasut wrote:
>>> On 06/01/2017 01:36 PM, patrice.chotard@st.com wrote:
>>>> From: Patrice Chotard <patrice.chotard@st.com>
>>>>
>>>> Add reset_count() method to be able to get the number
>>>> of resets contained into a resets property. This will allow
>>>> to allocate the right amount of memory in order to keep resets
>>>> reference. These resets reference can be used later on error path
>>>> or in .remove callback to release these resets.
>>>>
>>>> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
>>>> ---
>>>> v5:         _ replace fdtdec_parse_phandle_with_args() by dev_read_phandle_with_args()
>>>> v4:     _ add reset_count() method
>>>>
>>>>   drivers/reset/reset-uclass.c | 13 +++++++++++++
>>>>   include/reset.h              | 11 +++++++++++
>>>>   2 files changed, 24 insertions(+)
>>>>
>>>> diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
>>>> index 4fd82b9..4b17d4c 100644
>>>> --- a/drivers/reset/reset-uclass.c
>>>> +++ b/drivers/reset/reset-uclass.c
>>>> @@ -97,6 +97,19 @@ int reset_get_by_name(struct udevice *dev, const char *name,
>>>>     return reset_get_by_index(dev, index, reset_ctl);
>>>>   }
>>>>
>>>> +int reset_count(struct udevice *dev)
>>>> +{
>>>> +   int count;
>>>> +   struct ofnode_phandle_args args;
>>>> +
>>>> +   for (count = 0; ; count++) {
>>>> +           if (dev_read_phandle_with_args(dev,
>>>> +                                          "resets", "#reset-cells", 0,
>>>> +                                          count, &args))
>>>
>>> Don't we have some generic thing in libfdt to count number of phandle
>>> args ? This looks weird to me ...
>>
>> I didn't find anything in libfdt doing that.
>
> Maybe someone else can hop in, I'm quite sure there should be something
> like that.

In linux there is of_count_phandle_with_args(). Now that we have
livetree we could copy that function over. Then for flat tree we could
use fdtdec_parse_phandle_with_args() passing a -ve index.

Then we need something like dev_read_phandle_count().

Patrice what do you think?

Regards,
Simon
Patrice CHOTARD June 12, 2017, 7:27 a.m. UTC | #6
Hi Simon

On 06/06/2017 11:08 PM, Simon Glass wrote:
> Hi,

> 

> On 5 June 2017 at 05:18, Marek Vasut <marex@denx.de> wrote:

>> On 06/05/2017 11:34 AM, Patrice CHOTARD wrote:

>>> Hi Marek

>>>

>>> On 06/03/2017 08:02 AM, Marek Vasut wrote:

>>>> On 06/01/2017 01:36 PM, patrice.chotard@st.com wrote:

>>>>> From: Patrice Chotard <patrice.chotard@st.com>

>>>>>

>>>>> Add reset_count() method to be able to get the number

>>>>> of resets contained into a resets property. This will allow

>>>>> to allocate the right amount of memory in order to keep resets

>>>>> reference. These resets reference can be used later on error path

>>>>> or in .remove callback to release these resets.

>>>>>

>>>>> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

>>>>> ---

>>>>> v5:         _ replace fdtdec_parse_phandle_with_args() by dev_read_phandle_with_args()

>>>>> v4:     _ add reset_count() method

>>>>>

>>>>>    drivers/reset/reset-uclass.c | 13 +++++++++++++

>>>>>    include/reset.h              | 11 +++++++++++

>>>>>    2 files changed, 24 insertions(+)

>>>>>

>>>>> diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c

>>>>> index 4fd82b9..4b17d4c 100644

>>>>> --- a/drivers/reset/reset-uclass.c

>>>>> +++ b/drivers/reset/reset-uclass.c

>>>>> @@ -97,6 +97,19 @@ int reset_get_by_name(struct udevice *dev, const char *name,

>>>>>      return reset_get_by_index(dev, index, reset_ctl);

>>>>>    }

>>>>>

>>>>> +int reset_count(struct udevice *dev)

>>>>> +{

>>>>> +   int count;

>>>>> +   struct ofnode_phandle_args args;

>>>>> +

>>>>> +   for (count = 0; ; count++) {

>>>>> +           if (dev_read_phandle_with_args(dev,

>>>>> +                                          "resets", "#reset-cells", 0,

>>>>> +                                          count, &args))

>>>>

>>>> Don't we have some generic thing in libfdt to count number of phandle

>>>> args ? This looks weird to me ...

>>>

>>> I didn't find anything in libfdt doing that.

>>

>> Maybe someone else can hop in, I'm quite sure there should be something

>> like that.

> 

> In linux there is of_count_phandle_with_args(). Now that we have

> livetree we could copy that function over. Then for flat tree we could

> use fdtdec_parse_phandle_with_args() passing a -ve index.

> 

> Then we need something like dev_read_phandle_count().

> 

> Patrice what do you think?


Agree with that.
Ping me when this will be available, then i will update and resubmit my 
series.

Thanks

Patrice


> 

> Regards,

> Simon

>
Patrice CHOTARD June 12, 2017, 7:51 a.m. UTC | #7
On 06/12/2017 09:27 AM, Patrice CHOTARD wrote:
> Hi Simon

> 

> On 06/06/2017 11:08 PM, Simon Glass wrote:

>> Hi,

>>

>> On 5 June 2017 at 05:18, Marek Vasut <marex@denx.de> wrote:

>>> On 06/05/2017 11:34 AM, Patrice CHOTARD wrote:

>>>> Hi Marek

>>>>

>>>> On 06/03/2017 08:02 AM, Marek Vasut wrote:

>>>>> On 06/01/2017 01:36 PM, patrice.chotard@st.com wrote:

>>>>>> From: Patrice Chotard <patrice.chotard@st.com>

>>>>>>

>>>>>> Add reset_count() method to be able to get the number

>>>>>> of resets contained into a resets property. This will allow

>>>>>> to allocate the right amount of memory in order to keep resets

>>>>>> reference. These resets reference can be used later on error path

>>>>>> or in .remove callback to release these resets.

>>>>>>

>>>>>> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

>>>>>> ---

>>>>>> v5:         _ replace fdtdec_parse_phandle_with_args() by dev_read_phandle_with_args()

>>>>>> v4:     _ add reset_count() method

>>>>>>

>>>>>>     drivers/reset/reset-uclass.c | 13 +++++++++++++

>>>>>>     include/reset.h              | 11 +++++++++++

>>>>>>     2 files changed, 24 insertions(+)

>>>>>>

>>>>>> diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c

>>>>>> index 4fd82b9..4b17d4c 100644

>>>>>> --- a/drivers/reset/reset-uclass.c

>>>>>> +++ b/drivers/reset/reset-uclass.c

>>>>>> @@ -97,6 +97,19 @@ int reset_get_by_name(struct udevice *dev, const char *name,

>>>>>>       return reset_get_by_index(dev, index, reset_ctl);

>>>>>>     }

>>>>>>

>>>>>> +int reset_count(struct udevice *dev)

>>>>>> +{

>>>>>> +   int count;

>>>>>> +   struct ofnode_phandle_args args;

>>>>>> +

>>>>>> +   for (count = 0; ; count++) {

>>>>>> +           if (dev_read_phandle_with_args(dev,

>>>>>> +                                          "resets", "#reset-cells", 0,

>>>>>> +                                          count, &args))

>>>>>

>>>>> Don't we have some generic thing in libfdt to count number of phandle

>>>>> args ? This looks weird to me ...

>>>>

>>>> I didn't find anything in libfdt doing that.

>>>

>>> Maybe someone else can hop in, I'm quite sure there should be something

>>> like that.

>>

>> In linux there is of_count_phandle_with_args(). Now that we have

>> livetree we could copy that function over. Then for flat tree we could

>> use fdtdec_parse_phandle_with_args() passing a -ve index.

>>

>> Then we need something like dev_read_phandle_count().

>>

>> Patrice what do you think?

> 

> Agree with that.

> Ping me when this will be available, then i will update and resubmit my

> series.


Or do you prefer me to do this ? just tell me ?

> 

> Thanks

> 

> Patrice

> 

> 

>>

>> Regards,

>> Simon

>>

> _______________________________________________

> U-Boot mailing list

> U-Boot@lists.denx.de

> https://lists.denx.de/listinfo/u-boot

>
Patrice CHOTARD June 12, 2017, 7:52 a.m. UTC | #8
On 06/12/2017 09:27 AM, Patrice CHOTARD wrote:
> Hi Simon

> 

> On 06/06/2017 11:08 PM, Simon Glass wrote:

>> Hi,

>>

>> On 5 June 2017 at 05:18, Marek Vasut <marex@denx.de> wrote:

>>> On 06/05/2017 11:34 AM, Patrice CHOTARD wrote:

>>>> Hi Marek

>>>>

>>>> On 06/03/2017 08:02 AM, Marek Vasut wrote:

>>>>> On 06/01/2017 01:36 PM, patrice.chotard@st.com wrote:

>>>>>> From: Patrice Chotard <patrice.chotard@st.com>

>>>>>>

>>>>>> Add reset_count() method to be able to get the number

>>>>>> of resets contained into a resets property. This will allow

>>>>>> to allocate the right amount of memory in order to keep resets

>>>>>> reference. These resets reference can be used later on error path

>>>>>> or in .remove callback to release these resets.

>>>>>>

>>>>>> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

>>>>>> ---

>>>>>> v5:         _ replace fdtdec_parse_phandle_with_args() by dev_read_phandle_with_args()

>>>>>> v4:     _ add reset_count() method

>>>>>>

>>>>>>     drivers/reset/reset-uclass.c | 13 +++++++++++++

>>>>>>     include/reset.h              | 11 +++++++++++

>>>>>>     2 files changed, 24 insertions(+)

>>>>>>

>>>>>> diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c

>>>>>> index 4fd82b9..4b17d4c 100644

>>>>>> --- a/drivers/reset/reset-uclass.c

>>>>>> +++ b/drivers/reset/reset-uclass.c

>>>>>> @@ -97,6 +97,19 @@ int reset_get_by_name(struct udevice *dev, const char *name,

>>>>>>       return reset_get_by_index(dev, index, reset_ctl);

>>>>>>     }

>>>>>>

>>>>>> +int reset_count(struct udevice *dev)

>>>>>> +{

>>>>>> +   int count;

>>>>>> +   struct ofnode_phandle_args args;

>>>>>> +

>>>>>> +   for (count = 0; ; count++) {

>>>>>> +           if (dev_read_phandle_with_args(dev,

>>>>>> +                                          "resets", "#reset-cells", 0,

>>>>>> +                                          count, &args))

>>>>>

>>>>> Don't we have some generic thing in libfdt to count number of phandle

>>>>> args ? This looks weird to me ...

>>>>

>>>> I didn't find anything in libfdt doing that.

>>>

>>> Maybe someone else can hop in, I'm quite sure there should be something

>>> like that.

>>

>> In linux there is of_count_phandle_with_args(). Now that we have

>> livetree we could copy that function over. Then for flat tree we could

>> use fdtdec_parse_phandle_with_args() passing a -ve index.

>>

>> Then we need something like dev_read_phandle_count().

>>

>> Patrice what do you think?

> 

> Agree with that.

> Ping me when this will be available, then i will update and resubmit my

> series.


Or do you prefer me to do this ? just tell me

> 

> Thanks

> 

> Patrice

> 

> 

>>

>> Regards,

>> Simon

>>

> _______________________________________________

> U-Boot mailing list

> U-Boot@lists.denx.de

> https://lists.denx.de/listinfo/u-boot

>
Simon Glass June 12, 2017, 11:51 p.m. UTC | #9
Hi Patrice,

On 12 June 2017 at 01:51, Patrice CHOTARD <patrice.chotard@st.com> wrote:
>
>
> On 06/12/2017 09:27 AM, Patrice CHOTARD wrote:
>> Hi Simon
>>
>> On 06/06/2017 11:08 PM, Simon Glass wrote:
>>> Hi,
>>>
>>> On 5 June 2017 at 05:18, Marek Vasut <marex@denx.de> wrote:
>>>> On 06/05/2017 11:34 AM, Patrice CHOTARD wrote:
>>>>> Hi Marek
>>>>>
>>>>> On 06/03/2017 08:02 AM, Marek Vasut wrote:
>>>>>> On 06/01/2017 01:36 PM, patrice.chotard@st.com wrote:
>>>>>>> From: Patrice Chotard <patrice.chotard@st.com>
>>>>>>>
>>>>>>> Add reset_count() method to be able to get the number
>>>>>>> of resets contained into a resets property. This will allow
>>>>>>> to allocate the right amount of memory in order to keep resets
>>>>>>> reference. These resets reference can be used later on error path
>>>>>>> or in .remove callback to release these resets.
>>>>>>>
>>>>>>> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
>>>>>>> ---
>>>>>>> v5:         _ replace fdtdec_parse_phandle_with_args() by dev_read_phandle_with_args()
>>>>>>> v4:     _ add reset_count() method
>>>>>>>
>>>>>>>     drivers/reset/reset-uclass.c | 13 +++++++++++++
>>>>>>>     include/reset.h              | 11 +++++++++++
>>>>>>>     2 files changed, 24 insertions(+)
>>>>>>>
>>>>>>> diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
>>>>>>> index 4fd82b9..4b17d4c 100644
>>>>>>> --- a/drivers/reset/reset-uclass.c
>>>>>>> +++ b/drivers/reset/reset-uclass.c
>>>>>>> @@ -97,6 +97,19 @@ int reset_get_by_name(struct udevice *dev, const char *name,
>>>>>>>       return reset_get_by_index(dev, index, reset_ctl);
>>>>>>>     }
>>>>>>>
>>>>>>> +int reset_count(struct udevice *dev)
>>>>>>> +{
>>>>>>> +   int count;
>>>>>>> +   struct ofnode_phandle_args args;
>>>>>>> +
>>>>>>> +   for (count = 0; ; count++) {
>>>>>>> +           if (dev_read_phandle_with_args(dev,
>>>>>>> +                                          "resets", "#reset-cells", 0,
>>>>>>> +                                          count, &args))
>>>>>>
>>>>>> Don't we have some generic thing in libfdt to count number of phandle
>>>>>> args ? This looks weird to me ...
>>>>>
>>>>> I didn't find anything in libfdt doing that.
>>>>
>>>> Maybe someone else can hop in, I'm quite sure there should be something
>>>> like that.
>>>
>>> In linux there is of_count_phandle_with_args(). Now that we have
>>> livetree we could copy that function over. Then for flat tree we could
>>> use fdtdec_parse_phandle_with_args() passing a -ve index.
>>>
>>> Then we need something like dev_read_phandle_count().
>>>
>>> Patrice what do you think?
>>
>> Agree with that.
>> Ping me when this will be available, then i will update and resubmit my
>> series.
>
> Or do you prefer me to do this ? just tell me ?

Please go ahead, thanks.

Regards,
Simon
diff mbox

Patch

diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
index 4fd82b9..4b17d4c 100644
--- a/drivers/reset/reset-uclass.c
+++ b/drivers/reset/reset-uclass.c
@@ -97,6 +97,19 @@  int reset_get_by_name(struct udevice *dev, const char *name,
 	return reset_get_by_index(dev, index, reset_ctl);
 }
 
+int reset_count(struct udevice *dev)
+{
+	int count;
+	struct ofnode_phandle_args args;
+
+	for (count = 0; ; count++) {
+		if (dev_read_phandle_with_args(dev,
+					       "resets", "#reset-cells", 0,
+					       count, &args))
+			return count;
+	}
+}
+
 int reset_request(struct reset_ctl *reset_ctl)
 {
 	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
diff --git a/include/reset.h b/include/reset.h
index 4f2e35f..e8e68b6 100644
--- a/include/reset.h
+++ b/include/reset.h
@@ -100,6 +100,17 @@  int reset_get_by_name(struct udevice *dev, const char *name,
 		      struct reset_ctl *reset_ctl);
 
 /**
+ * reset_count - Get reset count contained in the "resets" property.
+ *
+ * This returns the count of reset found into the "resets" property. This
+ * allows to allocate the right amount of memory to keep reset reference.
+ *
+ * @dev:	The client device.
+ * @return number of resets found.
+ */
+int reset_count(struct udevice *dev);
+
+/**
  * reset_request - Request a reset signal.
  *
  * @reset_ctl:	A reset control struct.