Patchwork [U-Boot,v3,03/11] board:samsung: check the boot device and init the right mmc driver.

login
register
mail settings
Submitter Przemyslaw Marczak
Date June 26, 2014, 2:15 p.m.
Message ID <1403792137-3113-4-git-send-email-p.marczak@samsung.com>
Download mbox | patch
Permalink /patch/364558/
State Changes Requested
Delegated to: Minkyu Kang
Headers show

Comments

Przemyslaw Marczak - June 26, 2014, 2:15 p.m.
It is possible to boot device using a micro SD or eMMC slots.
In this situation, boot device should be registered as a block
device 0 in the MMC framework, because CONFIG_SYS_MMC_ENV_DEV
is usually set to "0" in the most config cases.

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
---
Changes V3:
- separate two changes into two commits
---
 board/samsung/common/board.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
Minkyu Kang - June 27, 2014, 9:40 a.m.
Dear Przemyslaw Marczak,

On 26/06/14 23:15, Przemyslaw Marczak wrote:
> It is possible to boot device using a micro SD or eMMC slots.
> In this situation, boot device should be registered as a block
> device 0 in the MMC framework, because CONFIG_SYS_MMC_ENV_DEV
> is usually set to "0" in the most config cases.
> 
> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
> ---
> Changes V3:
> - separate two changes into two commits
> ---
>  board/samsung/common/board.c | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/board/samsung/common/board.c b/board/samsung/common/board.c
> index ecf3f76..f07a900 100644
> --- a/board/samsung/common/board.c
> +++ b/board/samsung/common/board.c
> @@ -251,18 +251,28 @@ int board_mmc_init(bd_t *bis)
>  {
>  	int ret;
>  
> +	if (boot_device() == BOOT_DEVICE_SDMMC) {
> +#ifdef CONFIG_SDHCI
> +		/* mmc initializattion for available channels */
> +		ret = exynos_mmc_init(gd->fdt_blob);
> +#endif
>  #ifdef CONFIG_DWMMC
> -	/* dwmmc initializattion for available channels */
> -	ret = exynos_dwmmc_init(gd->fdt_blob);
> -	if (ret)
> -		debug("dwmmc init failed\n");
> +		/* dwmmc initializattion for available channels */
> +		ret = exynos_dwmmc_init(gd->fdt_blob);
> +#endif
> +	} else {
> +#ifdef CONFIG_DWMMC
> +		/* dwmmc initializattion for available channels */
> +		ret = exynos_dwmmc_init(gd->fdt_blob);
>  #endif
>  #ifdef CONFIG_SDHCI
> -	/* mmc initializattion for available channels */
> -	ret = exynos_mmc_init(gd->fdt_blob);
> +		/* mmc initializattion for available channels */
> +		ret = exynos_mmc_init(gd->fdt_blob);
> +#endif
> +	}
> +

It looks little confused.
Could you please re-arrange this code like this?

#ifdef CONFIG_SDHCI
	if (boot....) {

	} else {

	}
#endif

#ifdef CONFIG_DWMMC
	if (boot....) {

	} else {

	}
#endif

Thanks,
Minkyu Kang.
Jaehoon Chung - June 27, 2014, 9:45 a.m.
On 06/27/2014 06:40 PM, Minkyu Kang wrote:
> Dear Przemyslaw Marczak,
> 
> On 26/06/14 23:15, Przemyslaw Marczak wrote:
>> It is possible to boot device using a micro SD or eMMC slots.
>> In this situation, boot device should be registered as a block
>> device 0 in the MMC framework, because CONFIG_SYS_MMC_ENV_DEV
>> is usually set to "0" in the most config cases.
>>
>> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
>> ---
>> Changes V3:
>> - separate two changes into two commits
>> ---
>>  board/samsung/common/board.c | 24 +++++++++++++++++-------
>>  1 file changed, 17 insertions(+), 7 deletions(-)
>>
>> diff --git a/board/samsung/common/board.c b/board/samsung/common/board.c
>> index ecf3f76..f07a900 100644
>> --- a/board/samsung/common/board.c
>> +++ b/board/samsung/common/board.c
>> @@ -251,18 +251,28 @@ int board_mmc_init(bd_t *bis)
>>  {
>>  	int ret;
>>  
>> +	if (boot_device() == BOOT_DEVICE_SDMMC) {
>> +#ifdef CONFIG_SDHCI
>> +		/* mmc initializattion for available channels */
>> +		ret = exynos_mmc_init(gd->fdt_blob);
>> +#endif
>>  #ifdef CONFIG_DWMMC
>> -	/* dwmmc initializattion for available channels */
>> -	ret = exynos_dwmmc_init(gd->fdt_blob);
>> -	if (ret)
>> -		debug("dwmmc init failed\n");
>> +		/* dwmmc initializattion for available channels */
>> +		ret = exynos_dwmmc_init(gd->fdt_blob);
>> +#endif
>> +	} else {
>> +#ifdef CONFIG_DWMMC
>> +		/* dwmmc initializattion for available channels */
>> +		ret = exynos_dwmmc_init(gd->fdt_blob);
>>  #endif
>>  #ifdef CONFIG_SDHCI
>> -	/* mmc initializattion for available channels */
>> -	ret = exynos_mmc_init(gd->fdt_blob);
>> +		/* mmc initializattion for available channels */
>> +		ret = exynos_mmc_init(gd->fdt_blob);
>> +#endif
>> +	}
>> +
> 
> It looks little confused.
> Could you please re-arrange this code like this?

If re-arrange the below code, i want to call the dwmmc-init function at first.
Is there a special reason for sequence(sdhci->dwmmc)?

Best Regards,
Jaehoon Chung
> 
> #ifdef CONFIG_SDHCI
> 	if (boot....) {
> 
> 	} else {
> 
> 	}
> #endif
> 
> #ifdef CONFIG_DWMMC
> 	if (boot....) {
> 
> 	} else {
> 
> 	}
> #endif
> 
> Thanks,
> Minkyu Kang.
>
Przemyslaw Marczak - June 27, 2014, 11:34 a.m.
On 06/27/2014 11:40 AM, Minkyu Kang wrote:
> Dear Przemyslaw Marczak,
>
> On 26/06/14 23:15, Przemyslaw Marczak wrote:
>> It is possible to boot device using a micro SD or eMMC slots.
>> In this situation, boot device should be registered as a block
>> device 0 in the MMC framework, because CONFIG_SYS_MMC_ENV_DEV
>> is usually set to "0" in the most config cases.
>>
>> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
>> ---
>> Changes V3:
>> - separate two changes into two commits
>> ---
>>   board/samsung/common/board.c | 24 +++++++++++++++++-------
>>   1 file changed, 17 insertions(+), 7 deletions(-)
>>
>> diff --git a/board/samsung/common/board.c b/board/samsung/common/board.c
>> index ecf3f76..f07a900 100644
>> --- a/board/samsung/common/board.c
>> +++ b/board/samsung/common/board.c
>> @@ -251,18 +251,28 @@ int board_mmc_init(bd_t *bis)
>>   {
>>   	int ret;
>>
>> +	if (boot_device() == BOOT_DEVICE_SDMMC) {
>> +#ifdef CONFIG_SDHCI
>> +		/* mmc initializattion for available channels */
>> +		ret = exynos_mmc_init(gd->fdt_blob);
>> +#endif
>>   #ifdef CONFIG_DWMMC
>> -	/* dwmmc initializattion for available channels */
>> -	ret = exynos_dwmmc_init(gd->fdt_blob);
>> -	if (ret)
>> -		debug("dwmmc init failed\n");
>> +		/* dwmmc initializattion for available channels */
>> +		ret = exynos_dwmmc_init(gd->fdt_blob);
>> +#endif
>> +	} else {
>> +#ifdef CONFIG_DWMMC
>> +		/* dwmmc initializattion for available channels */
>> +		ret = exynos_dwmmc_init(gd->fdt_blob);
>>   #endif
>>   #ifdef CONFIG_SDHCI
>> -	/* mmc initializattion for available channels */
>> -	ret = exynos_mmc_init(gd->fdt_blob);
>> +		/* mmc initializattion for available channels */
>> +		ret = exynos_mmc_init(gd->fdt_blob);
>> +#endif
>> +	}
>> +
>
> It looks little confused.
> Could you please re-arrange this code like this?
>
> #ifdef CONFIG_SDHCI
> 	if (boot....) {
>
> 	} else {
>
> 	}
> #endif
>
> #ifdef CONFIG_DWMMC
> 	if (boot....) {
>
> 	} else {
>
> 	}
> #endif
>
> Thanks,
> Minkyu Kang.
>

There are few schemes:
- defined SDHCI and DWMMC or
- defined SDHCI only or
- defined DWMMC only or
So I need #ifdefs to take into account those all schemes.
To clean some mess I can do something like this:

static int init_sdhci(void) {
#ifdef CONFIG_SDHCI
	/* mmc initializattion for available channels */
	return exynos_mmc_init(gd->fdt_blob);
#else
	return 0;
#endif
}

static int init_dwmmc(void) {
#ifdef CONFIG_DWMMC
	/* dwmmc initializattion for available channels */
	return exynos_dwmmc_init(gd->fdt_blob);
#else
	return 0;
#endif
}

#ifdef CONFIG_GENERIC_MMC
int board_mmc_init(bd_t *bis)
{
	int ret;

	if (boot_device() == BOOT_DEVICE_SDMMC) {
		ret = init_sdhci();
		ret |= init_dwmmc();
	} else {
		ret = init_dwmmc();
		ret |= init_sdhci();
	}

	if (ret)
		debug("mmc init failed\n");

	return ret;
}
#endif

or with the ternary operator:

int board_mmc_init(bd_t *bis)
{
	int ret;
	int sd_boot = (boot_device() == BOOT_DEVICE_SDMMC);

	sd_boot ? ((ret = init_sdhci()) & (ret |= init_dwmmc()))
		 : ((ret = init_dwmmc()) & (ret |= init_sdhci()));

	if (ret)
		debug("mmc init failed\n");

	return ret;
}


Thank you,
Przemyslaw Marczak - June 27, 2014, 11:38 a.m.
hello Jaehoon,

On 06/27/2014 11:45 AM, Jaehoon Chung wrote:
> On 06/27/2014 06:40 PM, Minkyu Kang wrote:
>> Dear Przemyslaw Marczak,
>>
>> On 26/06/14 23:15, Przemyslaw Marczak wrote:
>>> It is possible to boot device using a micro SD or eMMC slots.
>>> In this situation, boot device should be registered as a block
>>> device 0 in the MMC framework, because CONFIG_SYS_MMC_ENV_DEV
>>> is usually set to "0" in the most config cases.
>>>
>>> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
>>> ---
>>> Changes V3:
>>> - separate two changes into two commits
>>> ---
>>>   board/samsung/common/board.c | 24 +++++++++++++++++-------
>>>   1 file changed, 17 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/board/samsung/common/board.c b/board/samsung/common/board.c
>>> index ecf3f76..f07a900 100644
>>> --- a/board/samsung/common/board.c
>>> +++ b/board/samsung/common/board.c
>>> @@ -251,18 +251,28 @@ int board_mmc_init(bd_t *bis)
>>>   {
>>>   	int ret;
>>>
>>> +	if (boot_device() == BOOT_DEVICE_SDMMC) {
>>> +#ifdef CONFIG_SDHCI
>>> +		/* mmc initializattion for available channels */
>>> +		ret = exynos_mmc_init(gd->fdt_blob);
>>> +#endif
>>>   #ifdef CONFIG_DWMMC
>>> -	/* dwmmc initializattion for available channels */
>>> -	ret = exynos_dwmmc_init(gd->fdt_blob);
>>> -	if (ret)
>>> -		debug("dwmmc init failed\n");
>>> +		/* dwmmc initializattion for available channels */
>>> +		ret = exynos_dwmmc_init(gd->fdt_blob);
>>> +#endif
>>> +	} else {
>>> +#ifdef CONFIG_DWMMC
>>> +		/* dwmmc initializattion for available channels */
>>> +		ret = exynos_dwmmc_init(gd->fdt_blob);
>>>   #endif
>>>   #ifdef CONFIG_SDHCI
>>> -	/* mmc initializattion for available channels */
>>> -	ret = exynos_mmc_init(gd->fdt_blob);
>>> +		/* mmc initializattion for available channels */
>>> +		ret = exynos_mmc_init(gd->fdt_blob);
>>> +#endif
>>> +	}
>>> +
>>
>> It looks little confused.
>> Could you please re-arrange this code like this?
>
> If re-arrange the below code, i want to call the dwmmc-init function at first.
> Is there a special reason for sequence(sdhci->dwmmc)?
>
> Best Regards,
> Jaehoon Chung

Please look at my proposed solution in the reply to Minkyu email.

Thanks,

Patch

diff --git a/board/samsung/common/board.c b/board/samsung/common/board.c
index ecf3f76..f07a900 100644
--- a/board/samsung/common/board.c
+++ b/board/samsung/common/board.c
@@ -251,18 +251,28 @@  int board_mmc_init(bd_t *bis)
 {
 	int ret;
 
+	if (boot_device() == BOOT_DEVICE_SDMMC) {
+#ifdef CONFIG_SDHCI
+		/* mmc initializattion for available channels */
+		ret = exynos_mmc_init(gd->fdt_blob);
+#endif
 #ifdef CONFIG_DWMMC
-	/* dwmmc initializattion for available channels */
-	ret = exynos_dwmmc_init(gd->fdt_blob);
-	if (ret)
-		debug("dwmmc init failed\n");
+		/* dwmmc initializattion for available channels */
+		ret = exynos_dwmmc_init(gd->fdt_blob);
+#endif
+	} else {
+#ifdef CONFIG_DWMMC
+		/* dwmmc initializattion for available channels */
+		ret = exynos_dwmmc_init(gd->fdt_blob);
 #endif
 #ifdef CONFIG_SDHCI
-	/* mmc initializattion for available channels */
-	ret = exynos_mmc_init(gd->fdt_blob);
+		/* mmc initializattion for available channels */
+		ret = exynos_mmc_init(gd->fdt_blob);
+#endif
+	}
+
 	if (ret)
 		debug("mmc init failed\n");
-#endif
 
 	return ret;
 }