diff mbox series

[1/2] usb: musb-new: sunxi: only perform SRAM initialization when necessary

Message ID 20230607231644.28203-2-CFSworks@gmail.com
State Superseded
Delegated to: Marek Vasut
Headers show
Series sunxi, usb: Clean up SRAM initialization code | expand

Commit Message

Sam Edwards June 7, 2023, 11:16 p.m. UTC
Only the older (ca. A10, A20) sunxis need this poke for the MUSB to
function. Mimic the Linux kernel and add a `has_sram` flag to the config
structure that is only set for the specific compatibles that require
this initialization.

Signed-off-by: Sam Edwards <CFSworks@gmail.com>
---
 drivers/usb/musb-new/sunxi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Andre Przywara June 8, 2023, 12:03 p.m. UTC | #1
On Wed,  7 Jun 2023 17:16:43 -0600
Sam Edwards <cfsworks@gmail.com> wrote:

> Only the older (ca. A10, A20) sunxis need this poke for the MUSB to
> function. Mimic the Linux kernel and add a `has_sram` flag to the config
> structure that is only set for the specific compatibles that require
> this initialization.

The patch looks alright in general, thanks for sending this! I will try to
test it on an older SoC in the next days. As an added bonus, that should
actually help the F1C100s USB(-OTG) support.

Cheers,
Andre

> Signed-off-by: Sam Edwards <CFSworks@gmail.com>
> ---
>  drivers/usb/musb-new/sunxi.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c
> index ab55d68620..c05c0d5561 100644
> --- a/drivers/usb/musb-new/sunxi.c
> +++ b/drivers/usb/musb-new/sunxi.c
> @@ -85,6 +85,7 @@
>  
>  struct sunxi_musb_config {
>  	struct musb_hdrc_config *config;
> +	bool has_sram;
>  };
>  
>  struct sunxi_glue {
> @@ -313,7 +314,10 @@ static int sunxi_musb_init(struct musb *musb)
>  
>  	musb->isr = sunxi_musb_interrupt;
>  
> -	USBC_ConfigFIFO_Base();
> +	if (glue->cfg->has_sram) {
> +		USBC_ConfigFIFO_Base();
> +	}
> +
>  	USBC_EnableDpDmPullUp(musb->mregs);
>  	USBC_EnableIdPullUp(musb->mregs);
>  
> @@ -525,6 +529,7 @@ static int musb_usb_remove(struct udevice *dev)
>  
>  static const struct sunxi_musb_config sun4i_a10_cfg = {
>  	.config = &musb_config,
> +	.has_sram = true,
>  };
>  
>  static const struct sunxi_musb_config sun6i_a31_cfg = {
Andre Przywara June 9, 2023, 10 a.m. UTC | #2
On Wed,  7 Jun 2023 17:16:43 -0600
Sam Edwards <cfsworks@gmail.com> wrote:

Hi,

> Only the older (ca. A10, A20) sunxis need this poke for the MUSB to
> function. Mimic the Linux kernel and add a `has_sram` flag to the config
> structure that is only set for the specific compatibles that require
> this initialization.

So I grabbed a BananaPi (A20) and played with it a little. Gadgets still
work with this patch, also I can confirm that this bit is necessary
(turned it off with mw.l, and the gadget stopped working), and also
that the bit flip works (set "has_sram = false;" and it didn't work anymore).

Also tested on an OrangePi Zero (H3), which doesn't need the SRAM switch.
It worked with both the bit set and cleared, also before and after the
patch, so it's all fine.

> Signed-off-by: Sam Edwards <CFSworks@gmail.com>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>
Tested-by: Andre Przywara <andre.przywara@arm.com>

Thanks,
Andre

> ---
>  drivers/usb/musb-new/sunxi.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c
> index ab55d68620..c05c0d5561 100644
> --- a/drivers/usb/musb-new/sunxi.c
> +++ b/drivers/usb/musb-new/sunxi.c
> @@ -85,6 +85,7 @@
>  
>  struct sunxi_musb_config {
>  	struct musb_hdrc_config *config;
> +	bool has_sram;
>  };
>  
>  struct sunxi_glue {
> @@ -313,7 +314,10 @@ static int sunxi_musb_init(struct musb *musb)
>  
>  	musb->isr = sunxi_musb_interrupt;
>  
> -	USBC_ConfigFIFO_Base();
> +	if (glue->cfg->has_sram) {
> +		USBC_ConfigFIFO_Base();
> +	}
> +
>  	USBC_EnableDpDmPullUp(musb->mregs);
>  	USBC_EnableIdPullUp(musb->mregs);
>  
> @@ -525,6 +529,7 @@ static int musb_usb_remove(struct udevice *dev)
>  
>  static const struct sunxi_musb_config sun4i_a10_cfg = {
>  	.config = &musb_config,
> +	.has_sram = true,
>  };
>  
>  static const struct sunxi_musb_config sun6i_a31_cfg = {
diff mbox series

Patch

diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c
index ab55d68620..c05c0d5561 100644
--- a/drivers/usb/musb-new/sunxi.c
+++ b/drivers/usb/musb-new/sunxi.c
@@ -85,6 +85,7 @@ 
 
 struct sunxi_musb_config {
 	struct musb_hdrc_config *config;
+	bool has_sram;
 };
 
 struct sunxi_glue {
@@ -313,7 +314,10 @@  static int sunxi_musb_init(struct musb *musb)
 
 	musb->isr = sunxi_musb_interrupt;
 
-	USBC_ConfigFIFO_Base();
+	if (glue->cfg->has_sram) {
+		USBC_ConfigFIFO_Base();
+	}
+
 	USBC_EnableDpDmPullUp(musb->mregs);
 	USBC_EnableIdPullUp(musb->mregs);
 
@@ -525,6 +529,7 @@  static int musb_usb_remove(struct udevice *dev)
 
 static const struct sunxi_musb_config sun4i_a10_cfg = {
 	.config = &musb_config,
+	.has_sram = true,
 };
 
 static const struct sunxi_musb_config sun6i_a31_cfg = {