Re: [U-Boot] [PATCH v4 04/11] clk: add clk_count()

2017-06-05 Thread Patrice CHOTARD
Hi Simon

On 06/01/2017 09:56 AM, Patrice CHOTARD wrote:
> Hi Simon
> 
> On 06/01/2017 05:10 AM, Simon Glass wrote:
>> Hi Patrice,
>>
>> On 24 May 2017 at 07:01,   wrote:
>>> From: Patrice Chotard 
>>>
>>> Add clk_count() method to be able to get the number
>>> of clocks contained into a clock property. This will allow
>>> to allocate the right amount of memory in order to keep clock
>>> reference. These clock reference can be used later on error path
>>> or in .remove callback to release these clocks.
>>>
>>> Signed-off-by: Patrice Chotard 
>>> ---
>>>
>>> v4: _ add clk_count() method
>>>
>>>drivers/clk/clk-uclass.c | 12 
>>>include/clk.h| 12 
>>>2 files changed, 24 insertions(+)
>>>
>>> diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
>>> index 6fcfd69..5c4dd19 100644
>>> --- a/drivers/clk/clk-uclass.c
>>> +++ b/drivers/clk/clk-uclass.c
>>> @@ -96,8 +96,20 @@ int clk_get_by_index(struct udevice *dev, int index, 
>>> struct clk *clk)
>>>
>>>   return clk_request(dev_clk, clk);
>>>}
>>> +
>>># endif /* OF_PLATDATA */
>>>
>>> +int clk_count(struct udevice *dev)
>>> +{
>>> +   int count;
>>> +   struct clk clk;
>>> +
>>> +   for (count = 0; ; count++) {
>>> +   if (clk_get_by_index(dev, count, ))
>>> +   return count;
>>> +   }
>>> +}
>>> +
>>>int clk_get_by_name(struct udevice *dev, const char *name, struct clk 
>>> *clk)
>>>{
>>>   int index;
>>> diff --git a/include/clk.h b/include/clk.h
>>> index 5a5c2ff..801920c 100644
>>> --- a/include/clk.h
>>> +++ b/include/clk.h
>>> @@ -98,6 +98,18 @@ int clk_get_by_index(struct udevice *dev, int index, 
>>> struct clk *clk);
>>> * @return 0 if OK, or a negative error code.
>>> */
>>>int clk_get_by_name(struct udevice *dev, const char *name, struct clk 
>>> *clk);
>>> +
>>> +/**
>>> + * clk_count - Get clock count contained in the "clocks" property.
>>> + *
>>> + * This returns the count of clock found into the "clocks" property. This
>>> + * allows to allocate the right amount of memory to keep clock reference.
>>
>> Can you document here that it 'gets' each clock and the clocks should
>> be freed? Or do you prefer to free the clocks within the function.
> 
> It don't 'gets' each clock, it just returns the number of "clocks"
> declared into the clocks property


Sorry, what i said above is wrong, you are right, my initial 
implementation of clk_count() used clk_get_by_index() which gets each clock.

I will rework clk_count() by using gev_read_phandle_with_args() as done 
for reset_count() in reset-uclass.c

Patrice

> 
> Patrice
> 
>>
>>> + *
>>> + * @dev:   The client device.
>>> + * @return number of clocks found.
>>> + */
>>> +int clk_count(struct udevice *dev);
>>> +
>>>#else
>>>static inline int clk_get_by_index(struct udevice *dev, int index,
>>>  struct clk *clk)
>>> --
>>> 1.9.1
>>>
>>
>> Regards,
>> Simon
>>
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
> 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 04/11] clk: add clk_count()

2017-06-01 Thread Patrice CHOTARD
Hi Simon

On 06/01/2017 05:10 AM, Simon Glass wrote:
> Hi Patrice,
> 
> On 24 May 2017 at 07:01,   wrote:
>> From: Patrice Chotard 
>>
>> Add clk_count() method to be able to get the number
>> of clocks contained into a clock property. This will allow
>> to allocate the right amount of memory in order to keep clock
>> reference. These clock reference can be used later on error path
>> or in .remove callback to release these clocks.
>>
>> Signed-off-by: Patrice Chotard 
>> ---
>>
>> v4: _ add clk_count() method
>>
>>   drivers/clk/clk-uclass.c | 12 
>>   include/clk.h| 12 
>>   2 files changed, 24 insertions(+)
>>
>> diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
>> index 6fcfd69..5c4dd19 100644
>> --- a/drivers/clk/clk-uclass.c
>> +++ b/drivers/clk/clk-uclass.c
>> @@ -96,8 +96,20 @@ int clk_get_by_index(struct udevice *dev, int index, 
>> struct clk *clk)
>>
>>  return clk_request(dev_clk, clk);
>>   }
>> +
>>   # endif /* OF_PLATDATA */
>>
>> +int clk_count(struct udevice *dev)
>> +{
>> +   int count;
>> +   struct clk clk;
>> +
>> +   for (count = 0; ; count++) {
>> +   if (clk_get_by_index(dev, count, ))
>> +   return count;
>> +   }
>> +}
>> +
>>   int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk)
>>   {
>>  int index;
>> diff --git a/include/clk.h b/include/clk.h
>> index 5a5c2ff..801920c 100644
>> --- a/include/clk.h
>> +++ b/include/clk.h
>> @@ -98,6 +98,18 @@ int clk_get_by_index(struct udevice *dev, int index, 
>> struct clk *clk);
>>* @return 0 if OK, or a negative error code.
>>*/
>>   int clk_get_by_name(struct udevice *dev, const char *name, struct clk 
>> *clk);
>> +
>> +/**
>> + * clk_count - Get clock count contained in the "clocks" property.
>> + *
>> + * This returns the count of clock found into the "clocks" property. This
>> + * allows to allocate the right amount of memory to keep clock reference.
> 
> Can you document here that it 'gets' each clock and the clocks should
> be freed? Or do you prefer to free the clocks within the function.

It don't 'gets' each clock, it just returns the number of "clocks" 
declared into the clocks property

Patrice

> 
>> + *
>> + * @dev:   The client device.
>> + * @return number of clocks found.
>> + */
>> +int clk_count(struct udevice *dev);
>> +
>>   #else
>>   static inline int clk_get_by_index(struct udevice *dev, int index,
>> struct clk *clk)
>> --
>> 1.9.1
>>
> 
> Regards,
> Simon
> 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 04/11] clk: add clk_count()

2017-05-31 Thread Simon Glass
Hi Patrice,

On 24 May 2017 at 07:01,   wrote:
> From: Patrice Chotard 
>
> Add clk_count() method to be able to get the number
> of clocks contained into a clock property. This will allow
> to allocate the right amount of memory in order to keep clock
> reference. These clock reference can be used later on error path
> or in .remove callback to release these clocks.
>
> Signed-off-by: Patrice Chotard 
> ---
>
> v4: _ add clk_count() method
>
>  drivers/clk/clk-uclass.c | 12 
>  include/clk.h| 12 
>  2 files changed, 24 insertions(+)
>
> diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
> index 6fcfd69..5c4dd19 100644
> --- a/drivers/clk/clk-uclass.c
> +++ b/drivers/clk/clk-uclass.c
> @@ -96,8 +96,20 @@ int clk_get_by_index(struct udevice *dev, int index, 
> struct clk *clk)
>
> return clk_request(dev_clk, clk);
>  }
> +
>  # endif /* OF_PLATDATA */
>
> +int clk_count(struct udevice *dev)
> +{
> +   int count;
> +   struct clk clk;
> +
> +   for (count = 0; ; count++) {
> +   if (clk_get_by_index(dev, count, ))
> +   return count;
> +   }
> +}
> +
>  int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk)
>  {
> int index;
> diff --git a/include/clk.h b/include/clk.h
> index 5a5c2ff..801920c 100644
> --- a/include/clk.h
> +++ b/include/clk.h
> @@ -98,6 +98,18 @@ int clk_get_by_index(struct udevice *dev, int index, 
> struct clk *clk);
>   * @return 0 if OK, or a negative error code.
>   */
>  int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk);
> +
> +/**
> + * clk_count - Get clock count contained in the "clocks" property.
> + *
> + * This returns the count of clock found into the "clocks" property. This
> + * allows to allocate the right amount of memory to keep clock reference.

Can you document here that it 'gets' each clock and the clocks should
be freed? Or do you prefer to free the clocks within the function.

> + *
> + * @dev:   The client device.
> + * @return number of clocks found.
> + */
> +int clk_count(struct udevice *dev);
> +
>  #else
>  static inline int clk_get_by_index(struct udevice *dev, int index,
>struct clk *clk)
> --
> 1.9.1
>

Regards,
Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 04/11] clk: add clk_count()

2017-05-24 Thread patrice.chotard
From: Patrice Chotard 

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

Signed-off-by: Patrice Chotard 
---

v4: _ add clk_count() method

 drivers/clk/clk-uclass.c | 12 
 include/clk.h| 12 
 2 files changed, 24 insertions(+)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 6fcfd69..5c4dd19 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -96,8 +96,20 @@ int clk_get_by_index(struct udevice *dev, int index, struct 
clk *clk)
 
return clk_request(dev_clk, clk);
 }
+
 # endif /* OF_PLATDATA */
 
+int clk_count(struct udevice *dev)
+{
+   int count;
+   struct clk clk;
+
+   for (count = 0; ; count++) {
+   if (clk_get_by_index(dev, count, ))
+   return count;
+   }
+}
+
 int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk)
 {
int index;
diff --git a/include/clk.h b/include/clk.h
index 5a5c2ff..801920c 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -98,6 +98,18 @@ int clk_get_by_index(struct udevice *dev, int index, struct 
clk *clk);
  * @return 0 if OK, or a negative error code.
  */
 int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk);
+
+/**
+ * clk_count - Get clock count contained in the "clocks" property.
+ *
+ * This returns the count of clock found into the "clocks" property. This
+ * allows to allocate the right amount of memory to keep clock reference.
+ *
+ * @dev:   The client device.
+ * @return number of clocks found.
+ */
+int clk_count(struct udevice *dev);
+
 #else
 static inline int clk_get_by_index(struct udevice *dev, int index,
   struct clk *clk)
-- 
1.9.1

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


[U-Boot] [PATCH v4 04/11] clk: add clk_count()

2017-05-24 Thread patrice.chotard
From: Patrice Chotard 

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

Signed-off-by: Patrice Chotard 
---

v4: _ add clk_count() method

 drivers/clk/clk-uclass.c | 12 
 include/clk.h| 12 
 2 files changed, 24 insertions(+)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 6fcfd69..5c4dd19 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -96,8 +96,20 @@ int clk_get_by_index(struct udevice *dev, int index, struct 
clk *clk)
 
return clk_request(dev_clk, clk);
 }
+
 # endif /* OF_PLATDATA */
 
+int clk_count(struct udevice *dev)
+{
+   int count;
+   struct clk clk;
+
+   for (count = 0; ; count++) {
+   if (clk_get_by_index(dev, count, ))
+   return count;
+   }
+}
+
 int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk)
 {
int index;
diff --git a/include/clk.h b/include/clk.h
index 5a5c2ff..801920c 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -98,6 +98,18 @@ int clk_get_by_index(struct udevice *dev, int index, struct 
clk *clk);
  * @return 0 if OK, or a negative error code.
  */
 int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk);
+
+/**
+ * clk_count - Get clock count contained in the "clocks" property.
+ *
+ * This returns the count of clock found into the "clocks" property. This
+ * allows to allocate the right amount of memory to keep clock reference.
+ *
+ * @dev:   The client device.
+ * @return number of clocks found.
+ */
+int clk_count(struct udevice *dev);
+
 #else
 static inline int clk_get_by_index(struct udevice *dev, int index,
   struct clk *clk)
-- 
1.9.1

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