usb: Extend ehci and ohci generic drivers
Subsystems (5)
v4 cover usb: Extend ehci and ohci generic drivers
From: Patrice Chotard <[email protected]>
This series improves generic ehci and ohci drivers by addition of :
_ error path during probe (clocks, resets and phy release) _ .remove callback
_ add generic PHY framework for both generic ehci and ohci drivers _ add RESET and CLOCK framework for generic ohci driver
To implement these features, some new methods are needed in RESET and CLOCKS frameworks :
_ add reset_request(), reset_count() and reset_assert_all() methods in
RESET framework
_ add clk_count() and add clk_disable_all() methods in CLOCK framework
v4: _ add clk_disable_all() and reset_assert_all() methods into CLOCK and
RESET framework as suggested by Simon Glass and Marek Vasut
_ add reset_count() and clk_count() methods which returns respectively the
number of resets and clocks declared into "resets" and "clocks" DT properties. This allows to allocate the right amount of memory to keep resets and clocks reference
_ update the memory allocation for deasserted resets and enabled
clocks reference list. Replace lists by arrays.
v3: _ keep enabled clocks and deasserted resets reference in list in order to
disable clock or assert resets in error path or in .remove callback
_ add missing commit message
_ use struct generic_ehci * instead of struct udevice * as parameter for
ehci_release_resets() and ehci_release_clocks()
_ test return value on generic_phy_get_by_index() and
generic_phy_init()
_ split previous patch 5 in 3 independant patch for CLOCK, RESET and PHY support
v2: _ add needed reset_request() in RESET framework
_ add error path in ehci/ohci-generic to disable clocks and to assert resets
_ add .remove callback with clocks, resets and phy release _ split the replacement of printf() by error() in an independant patch
Patrice Chotard (11):
reset: add reset_request()
reset: add reset_count()
reset: add reset_assert_all()
clk: add clk_count()
clk: add clk_disable_all()
usb: host: ehci-generic: replace printf() by error()
usb: host: ehci-generic: add error path and .remove callback
usb: host: ehci-generic: add generic PHY support
usb: host: ohci-generic: add CLOCK support
usb: host: ohci-generic: add RESET support
usb: host: ohci-generic: add generic PHY support
drivers/clk/clk-uclass.c | 34 ++++++++++ drivers/reset/reset-uclass.c | 45 +++++++++++++ drivers/usb/host/ehci-generic.c | 142 +++++++++++++++++++++++++++++++++------- drivers/usb/host/ohci-generic.c | 121 +++++++++++++++++++++++++++++++++- include/clk.h | 22 +++++++ include/reset.h | 37 +++++++++++ 6 files changed, 376 insertions(+), 25 deletions(-)
Signature · 1 line
1.9.1
PATCH v4 1/11 reset: add reset_request()
From: Patrice Chotard <[email protected]>
This is needed in error path to assert previously deasserted reset by using a saved reset_ctl reference.
---
v4: _ none
v3: _ none
v2: _ none
drivers/reset/reset-uclass.c | 9 +++++++++ include/reset.h | 9 +++++++++ 2 files changed, 18 insertions(+)
drivers/reset/reset-uclass.c +9 -0
@@ -98,6 +98,15 @@ int reset_get_by_name(struct udevice *dev, const char *name,return reset_get_by_index (dev, index, reset_ctl); } +int reset_request (struct reset_ctl *reset_ctl) +{ +struct reset_ops *ops =reset_dev_ops (reset_ctl->dev); + +debug ("%s(reset_ctl=%p)\n" , __func__, reset_ctl); + +return ops->request (reset_ctl); +} +int reset_free (struct reset_ctl *reset_ctl) {struct reset_ops *ops =reset_dev_ops (reset_ctl->dev);
include/reset.h +9 -0
@@ -100,6 +100,15 @@ int reset_get_by_name(struct udevice *dev, const char *name, struct reset_ctl *reset_ctl);/** +* reset_request - Request a reset signal. +* +* @reset_ctl: A reset control struct. +* +* @return 0 if OK, or a negative error code. +*/ +int reset_request (struct reset_ctl *reset_ctl); + +/** * reset_free - Free a previously requested reset signal. * * @reset_ctl: A reset control struct that was previously successfully
Signature · 1 line
1.9.1
PATCH v4 2/11 reset: add reset_count()
In reply to patrice.chotard at st.comFrom: Patrice Chotard <[email protected]>
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.
---
v4: _ add reset_count() method
drivers/reset/reset-uclass.c | 14 ++++++++++++++ include/reset.h | 11 +++++++++++ 2 files changed, 25 insertions(+)
drivers/reset/reset-uclass.c +14 -0
@@ -98,6 +98,20 @@ 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 fdtdec_phandle_args args; + +for (count =0 ; ; count++) { +if (fdtdec_parse_phandle_with_args (gd->fdt_blob, +dev_of_offset (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);
include/reset.h +11 -0
@@ -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.
Signature · 1 line
1.9.1
PATCH v4 2/11 reset: add reset_count()
Hi Patrice,
Quoted 25 lines · On 24 May 2017 at 07:01, <[email protected]> wrote:
From: Patrice Chotard <[email protected]>
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 <[email protected]>---
v4: _ add
reset_count()methoddrivers/reset/reset-uclass.c | 14 ++++++++++++++ include/reset.h | 11 +++++++++++ 2 files changed, 25 insertions(+)drivers/reset/reset-uclass.c +0
-0@@ -98,6 +98,20 @@ int reset_get_by_name(struct udevice *dev, const char *name,return reset_get_by_index (dev, index, reset_ctl); }
drivers/reset/reset-uclass.c int reset_get_by_name(struct udevice *dev, const char *name, · line 110
Quoted 10 lines
drivers/reset/reset-uclass.c +10
-0+int reset_count (struct udevice *dev) +{ +int count; +struct fdtdec_phandle_args args; + +for (count =0 ; ; count++) { +if (fdtdec_parse_phandle_with_args (gd->fdt_blob, +dev_of_offset (dev), +"resets" ,"#reset-cells" ,0 , + count, &args))
As I'm trying to get livetree support landed in U-Boot could you please rebase this on u-boot-dm/master? There is a new dev_read_phandle...() function.
Quoted 30 lines
drivers/reset/reset-uclass.c +4
-0+return count; + } +} +int reset_request (struct reset_ctl *reset_ctl) {struct reset_ops *ops =reset_dev_ops (reset_ctl->dev);include/reset.h +11
-1@@ -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. --
Quoted 2 lines
1.9.1
Regards,
Simon
PATCH v4 2/11 reset: add reset_count()
Hi Simon
Quoted 28 lines · Simon Glass
Hi Patrice,
Quoted 25 lines · On 24 May 2017 at 07:01, <[email protected]> wrote:
From: Patrice Chotard <[email protected]>
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 <[email protected]>---
v4: _ add
reset_count()methoddrivers/reset/reset-uclass.c | 14 ++++++++++++++ include/reset.h | 11 +++++++++++ 2 files changed, 25 insertions(+)drivers/reset/reset-uclass.c +0
-0@@ -98,6 +98,20 @@ int reset_get_by_name(struct udevice *dev, const char *name,return reset_get_by_index (dev, index, reset_ctl); }
Quoted 14 lines
drivers/reset/reset-uclass.c int reset_get_by_name(struct udevice *dev, const char *name, · line 110
Quoted 10 lines
drivers/reset/reset-uclass.c +10
-0+int reset_count (struct udevice *dev) +{ +int count; +struct fdtdec_phandle_args args; + +for (count =0 ; ; count++) { +if (fdtdec_parse_phandle_with_args (gd->fdt_blob, +dev_of_offset (dev), +"resets" ,"#reset-cells" ,0 , + count, &args))As I'm trying to get livetree support landed in U-Boot could you please rebase this on u-boot-dm/master? There is a new dev_read_phandle...() function.
Sure, i will then resubmit this series
Thanks
Patrice
Quoted 37 lines
Quoted 31 lines
drivers/reset/reset-uclass.c +4
-0+return count; + } +} +int reset_request (struct reset_ctl *reset_ctl) {struct reset_ops *ops =reset_dev_ops (reset_ctl->dev);include/reset.h +11
-1@@ -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. -- Quoted 2 lines
1.9.1
Regards,
Simon
PATCH v4 3/11 reset: add reset_assert_all()
In reply to patrice.chotard at st.comFrom: Patrice Chotard <[email protected]>
Add reset_assert_all() method which Request/Assert/Free an array of resets signal that has been previously successfully requested by reset_get_by_*()
---
v4: _ add reset_assert_all() method as suggested by Marek Vasut
and Simon Glass
drivers/reset/reset-uclass.c | 22 ++++++++++++++++++++++ include/reset.h | 17 +++++++++++++++++ 2 files changed, 39 insertions(+)
drivers/reset/reset-uclass.c +22 -0
@@ -148,6 +148,28 @@ int reset_deassert(struct reset_ctl *reset_ctl)return ops->rst_deassert (reset_ctl); } +int reset_assert_all (struct reset_ctl *reset_ctl,int count) +{ +int i, ret; + +for (i =0 ; i < count; i++) { +debug ("%s(reset_ctl[%d]=%p)\n" , __func__, i, &reset_ctl[i]); + + ret =reset_request (&reset_ctl[i]); +if (ret) +return ret; + + ret =reset_assert (&reset_ctl[i]); +if (ret) +return ret; + + ret =reset_free (&reset_ctl[i]); +if (ret) +return ret; + } +return 0 ; +} +UCLASS_DRIVER (reset) = { .id =UCLASS_RESET , .name ="reset" ,
include/reset.h +17 -0
@@ -155,6 +155,17 @@ int reset_assert(struct reset_ctl *reset_ctl);*/ int reset_deassert (struct reset_ctl *reset_ctl); +/** +* reset_assert_all - Request/Assert/Free resets. +* +* This function will request, assert and free array of clocks, +* +* @reset_ctl: A reset struct array that was previously successfully +* requested by reset_get_by_*(). +* @count Number of reset contained in the array +* @return 0 if OK, or a negative error code. +*/ +int reset_assert_all (struct reset_ctl *reset_ctl,int count);#else static inline int reset_get_by_index (struct udevice *dev,int index,struct reset_ctl *reset_ctl)
@@ -182,6 +193,12 @@ static inline int reset_deassert(struct reset_ctl *reset_ctl) {return 0 ; } + +static inline int reset_assert_all (struct reset_ctl *reset_ctl,int count) +{ +return 0 ; +} +#endif #endif
Signature · 1 line
1.9.1
PATCH v4 3/11 reset: add reset_assert_all()
Quoted 7 lines · On 24 May 2017 at 07:01, <[email protected]> wrote:
From: Patrice Chotard <[email protected]>
Add
reset_assert_all()method which Request/Assert/Free an array of resets signal that has been previously successfully requested by reset_get_by_*()Signed-off-by Patrice Chotard <[email protected]>
Quoted 8 lines
---
v4: _ add
reset_assert_all()method as suggested by Marek Vasut
and Simon Glassdrivers/reset/reset-uclass.c | 22 ++++++++++++++++++++++ include/reset.h | 17 +++++++++++++++++ 2 files changed, 39 insertions(+)
PATCH v4 4/11 clk: add clk_count()
In reply to patrice.chotard at st.comFrom: Patrice Chotard <[email protected]>
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.
---
v4: _ add clk_count() method
drivers/clk/clk-uclass.c | 12 ++++++++++++ include/clk.h | 12 ++++++++++++ 2 files changed, 24 insertions(+)
drivers/clk/clk-uclass.c +12 -0
@@ -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, &clk)) +return count; + } +} +int clk_get_by_name (struct udevice *dev,const char *name,struct clk *clk) {int index;
include/clk.h +12 -0
@@ -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)
Signature · 1 line
1.9.1
PATCH v4 4/11 clk: add clk_count()
Hi Patrice,
Quoted 47 lines · On 24 May 2017 at 07:01, <[email protected]> wrote:
From: Patrice Chotard <[email protected]>
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 <[email protected]>---
v4: _ add
clk_count()methoddrivers/clk/clk-uclass.c | 12 ++++++++++++ include/clk.h | 12 ++++++++++++ 2 files changed, 24 insertions(+)drivers/clk/clk-uclass.c +12
-0@@ -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, &clk)) +return count; + } +} +int clk_get_by_name (struct udevice *dev,const char *name,struct clk *clk) {int index;include/clk.h +0
-0
include/clk.h int clk_get_by_index(struct udevice *dev, int index, struct clk *clk); · line 106
Quoted 9 lines
include/clk.h +6
-0@@ -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.
Quoted 10 lines
include/clk.h +6
-1+* +* @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) --
Quoted 2 lines
1.9.1
Regards,
Simon
PATCH v4 4/11 clk: add clk_count()
Hi Simon
Quoted 54 lines · Simon Glass
Hi Patrice,
Quoted 51 lines · On 24 May 2017 at 07:01, <[email protected]> wrote:
From: Patrice Chotard <[email protected]>
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 <[email protected]>---
v4: _ add
clk_count()methoddrivers/clk/clk-uclass.c | 12 ++++++++++++ include/clk.h | 12 ++++++++++++ 2 files changed, 24 insertions(+)drivers/clk/clk-uclass.c +12
-0@@ -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, &clk)) +return count; + } +} +int clk_get_by_name (struct udevice *dev,const char *name,struct clk *clk) {int index;include/clk.h +1
-0@@ -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); +
Quoted 8 lines
include/clk.h int clk_get_by_index(struct udevice *dev, int index, struct clk *clk); · line 106
Quoted 5 lines
include/clk.h +5
-0+/** +* 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
Quoted 17 lines
Quoted 11 lines
include/clk.h +6
-1+* +* @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) --Quoted 2 lines
1.9.1
Regards,
Simon
PATCH v4 4/11 clk: add clk_count()
Hi Simon
Quoted 66 lines · Patrice CHOTARD
Hi Simon
Quoted 54 lines · Simon Glass
Hi Patrice,
Quoted 51 lines · On 24 May 2017 at 07:01, <[email protected]> wrote:
From: Patrice Chotard <[email protected]>
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 <[email protected]>---
v4: _ add
clk_count()methoddrivers/clk/clk-uclass.c | 12 ++++++++++++ include/clk.h | 12 ++++++++++++ 2 files changed, 24 insertions(+)drivers/clk/clk-uclass.c +12
-0@@ -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, &clk)) +return count; + } +} +int clk_get_by_name (struct udevice *dev,const char *name,struct clk *clk) {int index;include/clk.h +1
-0@@ -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); +Quoted 8 lines
include/clk.h int clk_get_by_index(struct udevice *dev, int index, struct clk *clk); · line 106
Quoted 5 lines
include/clk.h +5
-0+/** +* 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.
Quoted 2 lines
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
Quoted 25 lines
Patrice
Quoted 17 lines
Quoted 11 lines
include/clk.h +6
-1+* +* @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) --Quoted 2 lines
1.9.1
Regards,
Simon_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot
PATCH v4 5/11 clk: add clk_disable_all()
In reply to patrice.chotard at st.comFrom: Patrice Chotard <[email protected]>
Add clk_disable_all() method which Request/Disable/Free an array of clocks that has been previously requested by clk_request/get_by_*()
---
v4: _ add clk_disable_all() method as suggested by Marek Vasut
and Simon Glass
drivers/clk/clk-uclass.c | 22 ++++++++++++++++++++++ include/clk.h | 10 ++++++++++ 2 files changed, 32 insertions(+)
drivers/clk/clk-uclass.c +22 -0
@@ -201,6 +201,28 @@ int clk_disable(struct clk *clk)return ops->disable (clk); } +int clk_disable_all (struct clk *clk,int count) +{ +int i, ret; + +debug ("%s(clk=%p count=%d)\n" , __func__, clk, count); + +for (i =0 ; i < count; i++) { + ret =clk_request (clk->dev, &clk[i]); +if (ret && ret != -ENOSYS ) +return ret; + + ret =clk_disable (&clk[i]); +if (ret && ret != -ENOSYS ) +return ret; + + ret =clk_free (&clk[i]); +if (ret && ret != -ENOSYS ) +return ret; + } +return 0 ; +} +UCLASS_DRIVER (clk) = { .id =UCLASS_CLK , .name ="clk" ,
include/clk.h +10 -0
@@ -186,6 +186,16 @@ int clk_enable(struct clk *clk);*/ int clk_disable (struct clk *clk); +/** +* clk_disable_all() - Request/Disable (turn off)/Free clocks. +* +* @clk: A clock struct array that was previously successfully +* requested by clk_request/get_by_*(). +* @count Number of clock contained in the array +* @return zero on success, or -ve error code. +*/ +int clk_disable_all (struct clk *clk,int count); +int soc_clk_dump (void );#endif
Signature · 1 line
1.9.1
PATCH v4 6/11 usb: host: ehci-generic: replace printf() by error()
In reply to patrice.chotard at st.comFrom: Patrice Chotard <[email protected]>
This allows to get file, line and function location of the current error message.
---
v4: _ none
v3: _ add commit message
v2: _ create this independant path for printf() replacement
drivers/usb/host/ehci-generic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-generic.c +2 -2
@@ -34,7 +34,7 @@ static int ehci_usb_probe(struct udevice *dev)if (ret <0 )break ;if (clk_enable (&clk)) -printf ("failed to enable clock %d\n" , i); +error ("failed to enable clock %d\n" , i);clk_free (&clk); }
@@ -46,7 +46,7 @@ static int ehci_usb_probe(struct udevice *dev)if (ret <0 )break ;if (reset_deassert (&reset)) -printf ("failed to deassert reset %d\n" , i); +error ("failed to deassert reset %d\n" , i);reset_free (&reset); }
Signature · 1 line
1.9.1
PATCH v4 7/11 usb: host: ehci-generic: add error path and .remove callback
In reply to patrice.chotard at st.comFrom: Patrice Chotard <[email protected]>
Use an array to save enabled clocks reference and deasserted resets in order to respectively disabled and asserted them in case of error during probe() or during driver removal.
---
v4: _ update the memory allocation for deasserted resets and enabled
clocks reference list. Replace lists by arrays.
_ usage of new RESET and CLOCK methods clk_count(), reset_count(),v4
reset_assert_all() and clk_disable_all().
v3: _ keep enabled clocks and deasserted resets reference in list in order to
disable clock or assert resets in error path or in .remove callback
_ use struct generic_ehci * instead of struct udevice * as parameter for
ehci_release_resets() and ehci_release_clocks()
drivers/usb/host/ehci-generic.c | 114 +++++++++++++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 24 deletions(-)
drivers/usb/host/ehci-generic.c +90 -24
@@ -18,43 +18,109 @@*/ struct generic_ehci {struct ehci_ctrl ctrl; +struct clk *clocks; +struct reset_ctl *resets; +int clock_count; +int reset_count; };static int ehci_usb_probe (struct udevice *dev) { +struct generic_ehci *priv =dev_get_priv (dev);struct ehci_hccr *hccr;struct ehci_hcor *hcor; -int i; - -for (i =0 ; ; i++) { -struct clk clk; -int ret; - - ret =clk_get_by_index (dev, i, &clk); -if (ret <0 ) -break ; -if (clk_enable (&clk)) -error ("failed to enable clock %d\n" , i); -clk_free (&clk); - } +int i, err, ret, clock_nb, reset_nb; + + err =0 ; + priv->clock_count =0 ; + clock_nb =clk_count (dev); + +if (clock_nb) { + priv->clocks =devm_kmalloc (dev,sizeof (struct clk ) * clock_nb, +GFP_KERNEL ); +if (!priv->clocks) { +error ("Can't allocate resource\n" ); +return -ENOMEM ; + } + +for (i =0 ; i < clock_nb; i++) { + err =clk_get_by_index (dev, i, &priv->clocks[i]); + +if (err <0 ) +break ; -for (i =0 ; ; i++) { -struct reset_ctl reset; -int ret; + priv->clock_count++; - ret =reset_get_by_index (dev, i, &reset); -if (ret <0 ) -break ; -if (reset_deassert (&reset)) -error ("failed to deassert reset %d\n" , i); -reset_free (&reset); +if (clk_enable (&priv->clocks[i])) { +error ("failed to enable clock %d\n" , i); +clk_free (&priv->clocks[i]); + goto clk_err; + } +clk_free (&priv->clocks[i]); + } } + priv->reset_count =0 ; + reset_nb =reset_count (dev); + +if (reset_nb) { + priv->resets =devm_kmalloc (dev, +sizeof (struct reset_ctl ) * reset_nb, +GFP_KERNEL ); +if (!priv->resets) { +error ("Can't allocate resource\n" ); +return -ENOMEM ; + } + +for (i =0 ; i < reset_nb; i++) { + err =reset_get_by_index (dev, i, &priv->resets[i]); +if (err <0 ) +break ; + + priv->reset_count++; + +if (reset_deassert (&priv->resets[i])) { +error ("failed to deassert reset %d\n" , i); +reset_free (&priv->resets[i]); + goto reset_err; + } +reset_free (&priv->resets[i]); + } + } hccr =map_physmem (dev_get_addr (dev),0x100 ,MAP_NOCACHE ); hcor = (struct ehci_hcor *)((uintptr_t )hccr +HC_LENGTH (ehci_readl (&hccr->cr_capbase))); -return ehci_register (dev, hccr, hcor,NULL ,0 ,USB_INIT_HOST ); + err =ehci_register (dev, hccr, hcor,NULL ,0 ,USB_INIT_HOST ); +if (!err) +return err; + +reset_err: + ret =reset_assert_all (priv->resets, priv->reset_count); +if (ret) +return ret; +clk_err: + ret =clk_disable_all (priv->clocks, priv->clock_count); +if (ret) +return ret; + +return err; +} + +static int ehci_usb_remove (struct udevice *dev) +{ +struct generic_ehci *priv =dev_get_priv (dev); +int ret; + + ret =ehci_deregister (dev); +if (ret) +return ret; + + ret =reset_assert_all (priv->resets, priv->reset_count); +if (ret) +return ret; + +return clk_disable_all (priv->clocks, priv->clock_count); }static const struct udevice_id ehci_usb_ids[] = {
@@ -67,7 +133,7 @@ U_BOOT_DRIVER(ehci_generic) = { .id = UCLASS_USB, .of_match = ehci_usb_ids, .probe = ehci_usb_probe, - .remove = ehci_deregister, + .remove = ehci_usb_remove, .ops = &ehci_usb_ops, .priv_auto_alloc_size = sizeof(struct generic_ehci), .flags = DM_FLAG_ALLOC_PRIV_DMA,
Signature · 1 line
1.9.1
PATCH v4 7/11 usb: host: ehci-generic: add error path and .remove callback
Quoted 14 lines · On 24 May 2017 at 07:01, <[email protected]> wrote:
From: Patrice Chotard <[email protected]>
Use an array to save enabled clocks reference and deasserted resets in order to respectively disabled and asserted them in case of error during
probe()or during driver removal.Signed-off-by Patrice Chotard <[email protected]>---
v4: _ update the memory allocation for deasserted resets and enabled
clocks reference list. Replace lists by arrays.
_ usage of new RESET and CLOCK methodsclk_count(), reset_count(),v4
reset_assert_all()andclk_disable_all().
Quoted 7 lines
v3: _ keep enabled clocks and deasserted resets reference in list in order to
disable clock or assert resets in error path or in .remove callback
_ use structgeneric_ehci* instead of struct udevice * as parameter for
ehci_release_resets()andehci_release_clocks()drivers/usb/host/ehci-generic.c | 114 +++++++++++++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 24 deletions(-)
PATCH v4 8/11 usb: host: ehci-generic: add generic PHY support
In reply to patrice.chotard at st.comFrom: Patrice Chotard <[email protected]>
Extend ehci-generic driver with generic PHY framework
---
v4: _ use generic_phy_valid() before generic_phy_exit() call
v3: _ test return value on generic_phy_get_by_index() and
generic_phy_init()
drivers/usb/host/ehci-generic.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/usb/host/ehci-generic.c +30 -0
@@ -6,6 +6,8 @@#include <common.h> #include <clk.h> +#include <fdtdec.h> +#include <generic-phy.h> #include <reset.h> #include <asm/io.h> #include <dm.h>
@@ -20,6 +22,7 @@ struct generic_ehci {struct ehci_ctrl ctrl;struct clk *clocks;struct reset_ctl *resets; +struct phy phy;int clock_count;int reset_count; };
@@ -87,6 +90,21 @@ static int ehci_usb_probe(struct udevice *dev)reset_free (&priv->resets[i]); } } + + err =generic_phy_get_by_index (dev,0 , &priv->phy); +if (err) { +if (err != -ENOENT ) { +error ("failed to get usb phy\n" ); + goto reset_err; + } + }else { + err =generic_phy_init (&priv->phy); +if (err) { +error ("failed to init usb phy\n" ); + goto reset_err; + } + } + hccr =map_physmem (dev_get_addr (dev),0x100 ,MAP_NOCACHE ); hcor = (struct ehci_hcor *)((uintptr_t )hccr +HC_LENGTH (ehci_readl (&hccr->cr_capbase)));
@@ -95,6 +113,12 @@ static int ehci_usb_probe(struct udevice *dev)if (!err)return err; +if (generic_phy_valid (&priv->phy)) { + ret =generic_phy_exit (&priv->phy); +if (ret) +return ret; + } + reset_err: ret =reset_assert_all (priv->resets, priv->reset_count);if (ret)
@@ -116,6 +140,12 @@ static int ehci_usb_remove(struct udevice *dev)if (ret)return ret; +if (generic_phy_valid (&priv->phy)) { + ret =generic_phy_exit (&priv->phy); +if (ret) +return ret; + } + ret =reset_assert_all (priv->resets, priv->reset_count);if (ret)return ret;
Signature · 1 line
1.9.1
PATCH v4 8/11 usb: host: ehci-generic: add generic PHY support
Quoted 7 lines · On 24 May 2017 at 07:01, <[email protected]> wrote:
From: Patrice Chotard <[email protected]>
Extend ehci-generic driver with generic PHY framework
Signed-off-by Patrice Chotard <[email protected]>---
Quoted 9 lines
v4: _ use
generic_phy_valid()beforegeneric_phy_exit()callv3: _ test return value on
generic_phy_get_by_index()and
generic_phy_init()drivers/usb/host/ehci-generic.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
PATCH v4 9/11 usb: host: ohci-generic: add CLOCK support
In reply to patrice.chotard at st.comFrom: Patrice Chotard <[email protected]>
use array to save enabled clocks reference in order to disabled them in case of error during probe() or during driver removal.
---
v4: _ use generic_phy_valid() before generic_phy_exit() call
v3: _ extract in this patch the CLOCK support add-on from previous patch 5
_ keep enabled clocks reference in list in order to
disable clocks in error path or in .remove callback
v2: _ add error path management
_ add .remove callback
drivers/usb/host/ohci-generic.c | 53 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-)
drivers/usb/host/ohci-generic.c +51 -2
@@ -5,6 +5,7 @@*/ #include <common.h> +#include <clk.h> #include <dm.h> #include "ohci.h"
@@ -14,18 +15,66 @@struct generic_ohci {ohci_t ohci; +struct clk *clocks; +int clock_count; };static int ohci_usb_probe (struct udevice *dev) {struct ohci_regs *regs = (struct ohci_regs *)dev_get_addr (dev); +struct generic_ohci *priv =dev_get_priv (dev); +int i, err, ret, clock_nb; -return ohci_register (dev, regs); + err =0 ; + priv->clock_count =0 ; + clock_nb =clk_count (dev); + +if (clock_nb) { + priv->clocks =devm_kmalloc (dev,sizeof (struct clk ) * clock_nb, +GFP_KERNEL ); +if (!priv->clocks) { +error ("Can't allocate resource\n" ); +return -ENOMEM ; + } + +for (i =0 ; i < clock_nb; i++) { + err =clk_get_by_index (dev, i, &priv->clocks[i]); +if (err <0 ) +break ; + + priv->clock_count++; + +if (clk_enable (&priv->clocks[i])) { +error ("failed to enable clock %d\n" , i); +clk_free (&priv->clocks[i]); + goto clk_err; + } +clk_free (&priv->clocks[i]); + } + } + + err =ohci_register (dev, regs); +if (!err) +return err; + +clk_err: + ret =clk_disable_all (priv->clocks, priv->clock_count); +if (ret) +return ret; + +return err; }static int ohci_usb_remove (struct udevice *dev) { -return ohci_deregister (dev); +struct generic_ohci *priv =dev_get_priv (dev); +int ret; + + ret =ohci_deregister (dev); +if (ret) +return ret; + +return clk_disable_all (priv->clocks, priv->clock_count); }static const struct udevice_id ohci_usb_ids[] = {
Signature · 1 line
1.9.1
PATCH v4 9/11 usb: host: ohci-generic: add CLOCK support
Quoted 15 lines · On 24 May 2017 at 07:01, <[email protected]> wrote:
From: Patrice Chotard <[email protected]>
use array to save enabled clocks reference in order to disabled them in case of error during
probe()or during driver removal.Signed-off-by Patrice Chotard <[email protected]>---
v4: _ use
generic_phy_valid()beforegeneric_phy_exit()callv3: _ extract in this patch the CLOCK support add-on from previous patch 5
_ keep enabled clocks reference in list in order to
disable clocks in error path or in .remove callback
Quoted 6 lines
v2: _ add error path management
_ add .remove callbackdrivers/usb/host/ohci-generic.c | 53 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-)
PATCH v4 10/11 usb: host: ohci-generic: add RESET support
In reply to patrice.chotard at st.comFrom: Patrice Chotard <[email protected]>
use array to save deasserted resets reference in order to assert them in case of error during probe() or during driver removal.
---
v4: _ update the memory allocation for deasserted resets. Replace lists by arrays.
_ usage of new RESET methods reset_assert_all() and clk_disable_all().
v3: _ extract in this patch the RESET support add-on from previous patch 5
_ keep deasserted resets reference in list in order to
assert resets in error path or in .remove callback
v2: _ add error path management
_ add .remove callback
drivers/usb/host/ohci-generic.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)
drivers/usb/host/ohci-generic.c +40 -1
@@ -7,6 +7,7 @@#include <common.h> #include <clk.h> #include <dm.h> +#include <reset.h> #include "ohci.h" #if !defined(CONFIG_USB_OHCI_NEW )
@@ -16,14 +17,16 @@struct generic_ohci {ohci_t ohci;struct clk *clocks; +struct reset_ctl *resets;int clock_count; +int reset_count; };static int ohci_usb_probe (struct udevice *dev) {struct ohci_regs *regs = (struct ohci_regs *)dev_get_addr (dev);struct generic_ohci *priv =dev_get_priv (dev); -int i, err, ret, clock_nb; +int i, err, ret, clock_nb, reset_nb; err =0 ; priv->clock_count =0 ;
@@ -53,10 +56,42 @@ static int ohci_usb_probe(struct udevice *dev) } } + priv->reset_count =0 ; + reset_nb =reset_count (dev); + +if (reset_nb) { + priv->resets =devm_kmalloc (dev, +sizeof (struct reset_ctl ) * reset_nb, +GFP_KERNEL ); +if (!priv->resets) { +error ("Can't allocate resource\n" ); +return -ENOMEM ; + } + +for (i =0 ; i < reset_nb; i++) { + err =reset_get_by_index (dev, i, &priv->resets[i]); +if (err <0 ) +break ; + + priv->reset_count++; + +if (reset_deassert (&priv->resets[i])) { +error ("failed to deassert reset %d\n" , i); +reset_free (&priv->resets[i]); + goto reset_err; + } +reset_free (&priv->resets[i]); + } + } + err =ohci_register (dev, regs);if (!err)return err; +reset_err: + ret =reset_assert_all (priv->resets, priv->reset_count); +if (ret) +return ret; clk_err: ret =clk_disable_all (priv->clocks, priv->clock_count);if (ret)
@@ -74,6 +109,10 @@ static int ohci_usb_remove(struct udevice *dev)if (ret)return ret; + ret =reset_assert_all (priv->resets, priv->reset_count); +if (ret) +return ret; +return clk_disable_all (priv->clocks, priv->clock_count); }
Signature · 1 line
1.9.1
PATCH v4 10/11 usb: host: ohci-generic: add RESET support
Quoted 16 lines · On 24 May 2017 at 07:01, <[email protected]> wrote:
From: Patrice Chotard <[email protected]>
use array to save deasserted resets reference in order to assert them in case of error during
probe()or during driver removal.Signed-off-by Patrice Chotard <[email protected]>---
v4: _ update the memory allocation for deasserted resets. Replace lists by arrays.
_ usage of new RESET methodsreset_assert_all()andclk_disable_all().v3: _ extract in this patch the RESET support add-on from previous patch 5
_ keep deasserted resets reference in list in order to
assert resets in error path or in .remove callback
Quoted 6 lines
v2: _ add error path management
_ add .remove callbackdrivers/usb/host/ohci-generic.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)
PATCH v4 11/11 usb: host: ohci-generic: add generic PHY support
In reply to patrice.chotard at st.comFrom: Patrice Chotard <[email protected]>
Extend ohci-generic driver with generic PHY framework
---
v4: _ use generic_phy_valid() before generic_phy_exit() call
v3: _ extract in this patch the PHY support add-on from previous patch 5
drivers/usb/host/ohci-generic.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
drivers/usb/host/ohci-generic.c +29 -0
@@ -6,6 +6,8 @@#include <common.h> #include <clk.h> +#include <fdtdec.h> +#include <generic-phy.h> #include <dm.h> #include <reset.h> #include "ohci.h"
@@ -18,6 +20,7 @@ struct generic_ohci {ohci_t ohci;struct clk *clocks;struct reset_ctl *resets; +struct phy phy;int clock_count;int reset_count; };
@@ -84,10 +87,30 @@ static int ohci_usb_probe(struct udevice *dev) } } + err =generic_phy_get_by_index (dev,0 , &priv->phy); +if (err) { +if (err != -ENOENT ) { +error ("failed to get usb phy\n" ); + goto reset_err; + } + }else { + err =generic_phy_init (&priv->phy); +if (err) { +error ("failed to init usb phy\n" ); + goto reset_err; + } + } + err =ohci_register (dev, regs);if (!err)return err; +if (generic_phy_valid (&priv->phy)) { + ret =generic_phy_exit (&priv->phy); +if (ret) +return ret; + } + reset_err: ret =reset_assert_all (priv->resets, priv->reset_count);if (ret)
@@ -109,6 +132,12 @@ static int ohci_usb_remove(struct udevice *dev)if (ret)return ret; +if (generic_phy_valid (&priv->phy)) { + ret =generic_phy_exit (&priv->phy); +if (ret) +return ret; + } + ret =reset_assert_all (priv->resets, priv->reset_count);if (ret)return ret;
Signature · 1 line
1.9.1
PATCH v4 11/11 usb: host: ohci-generic: add generic PHY support
Quoted 5 lines · On 24 May 2017 at 07:01, <[email protected]> wrote:
From: Patrice Chotard <[email protected]>
Extend ohci-generic driver with generic PHY framework
Signed-off-by Patrice Chotard <[email protected]>
Quoted 8 lines
---
v4: _ use
generic_phy_valid()beforegeneric_phy_exit()callv3: _ extract in this patch the PHY support add-on from previous patch 5
drivers/usb/host/ohci-generic.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
v4 cover usb: Extend ehci and ohci generic drivers
In reply to patrice.chotard at st.comSorry, "U-boot" is missing is all patches subject. I will resend this series with the correct subject
Patrice
Quoted 59 lines · patrice.chotard at st.com
From: Patrice Chotard <[email protected]>
This series improves generic ehci and ohci drivers by addition of :
_ error path during probe (clocks, resets and phy release) _ .remove callback
_ add generic PHY framework for both generic ehci and ohci drivers _ add RESET and CLOCK framework for generic ohci driverTo implement these features, some new methods are needed in RESET and CLOCKS frameworks :
_ addreset_request(),reset_count()andreset_assert_all()methods in
RESET framework
_ addclk_count()and addclk_disable_all()methods in CLOCK frameworkv4: _ add
clk_disable_all()andreset_assert_all()methods into CLOCK and
RESET framework as suggested by Simon Glass and Marek Vasut
_ addreset_count()andclk_count()methods which returns respectively the
number of resets and clocks declared into "resets" and "clocks" DT properties. This allows to allocate the right amount of memory to keep resets and clocks reference
_ update the memory allocation for deasserted resets and enabled
clocks reference list. Replace lists by arrays.v3: _ keep enabled clocks and deasserted resets reference in list in order to
disable clock or assert resets in error path or in .remove callback
_ add missing commit message
_ use structgeneric_ehci* instead of struct udevice * as parameter for
ehci_release_resets()andehci_release_clocks()
_ test return value ongeneric_phy_get_by_index()and
generic_phy_init()
_ split previous patch 5 in 3 independant patch for CLOCK, RESET and PHY supportv2: _ add needed
reset_request()in RESET framework
_ add error path in ehci/ohci-generic to disable clocks and to assert resets
_ add .remove callback with clocks, resets and phy release _ split the replacement ofprintf()byerror()in an independant patchPatrice Chotard (11):
reset: addreset_request()
reset: addreset_count()
reset: addreset_assert_all()
clk: addclk_count()
clk: addclk_disable_all()
usb: host: ehci-generic: replaceprintf()byerror()
usb: host: ehci-generic: add error path and .remove callback
usb: host: ehci-generic: add generic PHY support
usb: host: ohci-generic: add CLOCK support
usb: host: ohci-generic: add RESET support
usb: host: ohci-generic: add generic PHY supportdrivers/clk/clk-uclass.c | 34 ++++++++++ drivers/reset/reset-uclass.c | 45 +++++++++++++ drivers/usb/host/ehci-generic.c | 142 +++++++++++++++++++++++++++++++++------- drivers/usb/host/ohci-generic.c | 121 +++++++++++++++++++++++++++++++++- include/clk.h | 22 +++++++ include/reset.h | 37 +++++++++++ 6 files changed, 376 insertions(+), 25 deletions(-)