diff mbox

[U-Boot] am33xx: board: Refactor USB initialization into separate function

Message ID 20170206223013.28668-1-alex.g@adaptrum.com
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Alexandru Gagniuc Feb. 6, 2017, 10:30 p.m. UTC
The declaration of otg*_plat and otg*_board_data is guarded by
CONFIG_USB_MUSB_*, but their use in arch_misc_init is not. The
ifdef flow goes something like:

if (CONFIG_USB_MUSB_* && other_conditions)
	declare usb_data
if (other_conditions)
	use usb_data

Thus when CONFIG_USB_MUSB_* is not declared, we try to use the
data structures, but these structures aren't defined.

To fix this, move the USB initialization code into the same #ifdef
which guards the declaration of the data structures. Split the USB
init into two identically named symbols, for ease of readability.

Signed-off-by: Alexandru Gagniuc <alex.g@adaptrum.com>
---
 arch/arm/mach-omap2/am33xx/board.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

Comments

Andreas Färber Feb. 12, 2017, 1:55 p.m. UTC | #1
Am 06.02.2017 um 23:30 schrieb Alexandru Gagniuc:
> diff --git a/arch/arm/mach-omap2/am33xx/board.c b/arch/arm/mach-omap2/am33xx/board.c
> index 190310f..f19e919 100644
> --- a/arch/arm/mach-omap2/am33xx/board.c
> +++ b/arch/arm/mach-omap2/am33xx/board.c
> @@ -190,11 +190,9 @@ static struct musb_hdrc_platform_data otg1_plat = {
>  	.board_data	= &otg1_board_data,
>  };
>  #endif
> -#endif
>  
> -int arch_misc_init(void)
> +static int arch_usb_init(void)
>  {
> -#ifndef CONFIG_DM_USB
>  #ifdef CONFIG_AM335X_USB0
>  	musb_register(&otg0_plat, &otg0_board_data,
>  		(void *)USB0_OTG_BASE);
> @@ -203,7 +201,13 @@ int arch_misc_init(void)
>  	musb_register(&otg1_plat, &otg1_board_data,
>  		(void *)USB1_OTG_BASE);
>  #endif
> -#else
> +	return 0;
> +}
> +
> +#else	/* CONFIG_USB_MUSB_* && CONFIG_AM335X_USB* && !CONFIG_DM_USB */
> +
> +int static int arch_usb_init(void)(void)

This looks like a copy&paste gone wrong.

Regards,
Andreas

> +{
>  	struct udevice *dev;
>  	int ret;
>  
> @@ -211,6 +215,19 @@ int arch_misc_init(void)
>  	if (ret || !dev)
>  		return ret;
>  
> +	return 0;
> +}
> +
> +#endif /* CONFIG_USB_MUSB_* && CONFIG_AM335X_USB* && !CONFIG_DM_USB */
[snip]
Alexandru Gagniuc Feb. 13, 2017, 5:18 p.m. UTC | #2
On 02/12/2017 05:55 AM, Andreas Färber wrote:
> Am 06.02.2017 um 23:30 schrieb Alexandru Gagniuc:
>> diff --git a/arch/arm/mach-omap2/am33xx/board.c b/arch/arm/mach-omap2/am33xx/board.c
>> index 190310f..f19e919 100644
>> --- a/arch/arm/mach-omap2/am33xx/board.c
>> +++ b/arch/arm/mach-omap2/am33xx/board.c
>> @@ -190,11 +190,9 @@ static struct musb_hdrc_platform_data otg1_plat = {
>>  	.board_data	= &otg1_board_data,
>>  };
>>  #endif
>> -#endif
>>
>> -int arch_misc_init(void)
>> +static int arch_usb_init(void)
>>  {
>> -#ifndef CONFIG_DM_USB
>>  #ifdef CONFIG_AM335X_USB0
>>  	musb_register(&otg0_plat, &otg0_board_data,
>>  		(void *)USB0_OTG_BASE);
>> @@ -203,7 +201,13 @@ int arch_misc_init(void)
>>  	musb_register(&otg1_plat, &otg1_board_data,
>>  		(void *)USB1_OTG_BASE);
>>  #endif
>> -#else
>> +	return 0;
>> +}
>> +
>> +#else	/* CONFIG_USB_MUSB_* && CONFIG_AM335X_USB* && !CONFIG_DM_USB */
>> +
>> +int static int arch_usb_init(void)(void)
>
> This looks like a copy&paste gone wrong.

This was fixed in V2.

Alex

> Regards,
> Andreas
>
>> +{
>>  	struct udevice *dev;
>>  	int ret;
>>
>> @@ -211,6 +215,19 @@ int arch_misc_init(void)
>>  	if (ret || !dev)
>>  		return ret;
>>
>> +	return 0;
>> +}
>> +
>> +#endif /* CONFIG_USB_MUSB_* && CONFIG_AM335X_USB* && !CONFIG_DM_USB */
> [snip]
>
diff mbox

Patch

diff --git a/arch/arm/mach-omap2/am33xx/board.c b/arch/arm/mach-omap2/am33xx/board.c
index 190310f..f19e919 100644
--- a/arch/arm/mach-omap2/am33xx/board.c
+++ b/arch/arm/mach-omap2/am33xx/board.c
@@ -190,11 +190,9 @@  static struct musb_hdrc_platform_data otg1_plat = {
 	.board_data	= &otg1_board_data,
 };
 #endif
-#endif
 
-int arch_misc_init(void)
+static int arch_usb_init(void)
 {
-#ifndef CONFIG_DM_USB
 #ifdef CONFIG_AM335X_USB0
 	musb_register(&otg0_plat, &otg0_board_data,
 		(void *)USB0_OTG_BASE);
@@ -203,7 +201,13 @@  int arch_misc_init(void)
 	musb_register(&otg1_plat, &otg1_board_data,
 		(void *)USB1_OTG_BASE);
 #endif
-#else
+	return 0;
+}
+
+#else	/* CONFIG_USB_MUSB_* && CONFIG_AM335X_USB* && !CONFIG_DM_USB */
+
+int static int arch_usb_init(void)(void)
+{
 	struct udevice *dev;
 	int ret;
 
@@ -211,6 +215,19 @@  int arch_misc_init(void)
 	if (ret || !dev)
 		return ret;
 
+	return 0;
+}
+
+#endif /* CONFIG_USB_MUSB_* && CONFIG_AM335X_USB* && !CONFIG_DM_USB */
+
+int arch_misc_init(void)
+{
+	int ret;
+
+	ret = arch_usb_init();
+	if (ret)
+		return ret;
+
 #if defined(CONFIG_DM_ETH) && defined(CONFIG_USB_ETHER)
 	ret = usb_ether_init();
 	if (ret) {
@@ -218,7 +235,6 @@  int arch_misc_init(void)
 		return ret;
 	}
 #endif
-#endif
 	return 0;
 }