[U-Boot] [PATCH] drivers:usb:common:fsl-dt-fixup: Fix the dt for all type of usb controllers

Marek Vasut marex at denx.de
Mon Jun 20 16:16:30 CEST 2016


On 06/20/2016 06:15 AM, Sriram Dash wrote:
> Currently, U-boot doesn't allow to compile more than one type of USB protocol
> simultaneously. Hence, EHCI and XHCI controllers cannot co-exist and
> CONFIG_USB_MAX_CONTROLLER_COUNT macro represents count of only one type of
> controller.

This does not make sense, with DM we can support all sorts of controllers.

> For the Socs which have more than one type of controller e.g. EHCI and XHCI,
> and the device tree has to support both of them, the macro
> CONFIG_USB_MAX_CONTROLLER_COUNT will not work for fixing dt from u boot.
> 
> So, instead of taking the hard coded number of controller from U boot,
> count the total number of controller present in dt and then fix the dt
> accordingly.
> 
> Signed-off-by: Sriram Dash <sriram.dash at nxp.com>
> Signed-off-by: Rajesh Bhagat <rajesh.bhagat at nxp.com>
> ---
>  drivers/usb/common/fsl-dt-fixup.c | 27 ++++++++++++++++++++++++++-
>  1 file changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/common/fsl-dt-fixup.c b/drivers/usb/common/fsl-dt-fixup.c
> index 9c48852..1edf146 100644
> --- a/drivers/usb/common/fsl-dt-fixup.c
> +++ b/drivers/usb/common/fsl-dt-fixup.c
> @@ -131,10 +131,29 @@ static int fdt_fixup_erratum(int *usb_erratum_off, void *blob,
>  	return 0;
>  }
>  
> +static int fdt_max_controller_count(void *blob)
> +{
> +	int count = 0;
> +	int node_offset = -1;
> +	int i;
> +
> +	for (i = 0; compat_usb_fsl[i]; i++) {
> +		do {
> +			node_offset = fdt_node_offset_by_compatible
> +					(blob, node_offset,
> +					 compat_usb_fsl[i]);
> +			if (node_offset >= 0)
> +				count++;
> +		} while (node_offset != -FDT_ERR_NOTFOUND);
> +	}
> +	return count;
> +}
> +
>  void fdt_fixup_dr_usb(void *blob, bd_t *bd)
>  {
>  	static const char * const modes[] = { "host", "peripheral", "otg" };
>  	static const char * const phys[] = { "ulpi", "utmi", "utmi_dual" };
> +	unsigned int usb_max_controller_count;
>  	int usb_erratum_a006261_off = -1;
>  	int usb_erratum_a007075_off = -1;
>  	int usb_erratum_a007792_off = -1;
> @@ -146,7 +165,13 @@ void fdt_fixup_dr_usb(void *blob, bd_t *bd)
>  	int i, j;
>  	int ret;
>  
> -	for (i = 1; i <= CONFIG_USB_MAX_CONTROLLER_COUNT; i++) {
> +	usb_max_controller_count = fdt_max_controller_count(blob);

Since you walk the tree below anyway, why do you even need to count the
elements? Just walk the tree until you can find no more nodes.

> +	if (!usb_max_controller_count) {
> +		printf("ERROR: FDT fixup erratum fail.\n");
> +		return;
> +	}
> +
> +	for (i = 1; i <= usb_max_controller_count; i++) {
>  		const char *dr_mode_type = NULL;
>  		const char *dr_phy_type = NULL;
>  		int mode_idx = -1, phy_idx = -1;
> 


-- 
Best regards,
Marek Vasut


More information about the U-Boot mailing list