Skip to contentSkip to conversation

arm: trats: add the sd-card power control function.

PATCH New Jaehoon Chung 3 participants 5 messages Oct 31, 2013 – Nov 4, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: trats: add the sd-card power control function.

To use the sd-card, VTF_2.8V will be enabled.
Before this patch, VTF_2.8V is always disabled.(card can't initialize.) When card is detected, SD-card power will enable with sd_ldo_control().

---
 board/samsung/trats/trats.c |   38 ++++++++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)
board/samsung/trats/trats.c +32 -6
index 7f61d17..9b6dd12 100644
@@ -408,11 +408,31 @@ int checkboard(void)
 #endif
 
 #ifdef CONFIG_GENERIC_MMC
+static int sd_ldo_control(int on)
+{
+	struct pmic *p = pmic_get("MAX8997_PMIC");
+	u32 val = 0;
+	int ret = 0;
+	if (pmic_probe(p))
+		return -1;
+
+	/* LDO17 VTF: 2.8V */
+	val = max8997_reg_ldo(2800000) | (on? EN_LDO : DIS_LDO);
+	ret |= pmic_reg_write(p, MAX8997_REG_LDO17CTRL, val);
+
+	if (ret) {
+		puts("MAX8997 SD setting error!\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 int board_mmc_init(bd_t *bis)
 {
 	struct exynos4_gpio_part2 *gpio =
 		(struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
-	int err;
+	int err, err_sd = 0;
 
 	/* eMMC_EN: SD_0_CDn: GPK0[2] Output High */
 	s5p_gpio_direction_output(&gpio->k0, 2, 1);
@@ -438,14 +458,20 @@ int board_mmc_init(bd_t *bis)
 	 * GPX3[4] T-flash detect pin
 	 */
 	if (!s5p_gpio_get_value(&gpio->x3, 4)) {
-		err = exynos_pinmux_config(PERIPH_ID_SDMMC2, PINMUX_FLAG_NONE);
-		if (err)
+		err_sd = exynos_pinmux_config(PERIPH_ID_SDMMC2, PINMUX_FLAG_NONE);
+		if (err_sd)
 			debug("SDMMC2 not configured\n");
-		else
-			err = s5p_mmc_init(2, 4);
+		else {
+			if (!sd_ldo_control(1)) {
+				err_sd = s5p_mmc_init(2, 4);
+				if (err_sd) {
+					sd_ldo_control(0);
+				}
+			}
+		}
 	}
 
-	return err;
+	return err & err_sd;
 }
 #endif
 
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 arm: trats: add the sd-card power control function.

Hi Jaehoon,

Quoted 17 lines

To use the sd-card, VTF_2.8V will be enabled.
Before this patch, VTF_2.8V is always disabled.(card can't initialize.) When card is detected, SD-card power will enable with sd_ldo_control().

---
 board/samsung/trats/trats.c |   38

++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-)

board/samsung/trats/trats.c +0 -0
index 7f61d17..9b6dd12 100644

board/samsung/trats/trats.c int checkboard(void) · line 417

Quoted 10 lines
board/samsung/trats/trats.c +7 -0
@@ -408,11 +408,31 @@ int checkboard(void)
 #endif
 
 #ifdef CONFIG_GENERIC_MMC
+static int sd_ldo_control(int on)
+{
+	struct pmic *p = pmic_get("MAX8997_PMIC");
+	u32 val = 0;
+	int ret = 0;
+	if (pmic_probe(p))
+		return -1;

Maybe -1 -> -ENODEV

board/samsung/trats/trats.c int checkboard(void) · line 420

Quoted 3 lines
board/samsung/trats/trats.c +3 -0
+
+	/* LDO17 VTF: 2.8V */
+	val = max8997_reg_ldo(2800000) | (on? EN_LDO : DIS_LDO);
                                          ^^^ on ?

board/samsung/trats/trats.c int checkboard(void) · line 421

Quoted 1 line
board/samsung/trats/trats.c +1 -0
+	ret |= pmic_reg_write(p, MAX8997_REG_LDO17CTRL, val);
	^^^^^ ret = 

board/samsung/trats/trats.c int checkboard(void) · line 424

Quoted 3 lines
board/samsung/trats/trats.c +3 -0
+
+	if (ret) {
+		puts("MAX8997 SD setting error!\n");

Please use error() instead of puts()

board/samsung/trats/trats.c int checkboard(void) · line 435

Quoted 13 lines
board/samsung/trats/trats.c +7 -1
+		return -1;
+	}
+
+	return 0;
+}
+
 int board_mmc_init(bd_t *bis)
 {
 	struct exynos4_gpio_part2 *gpio =
 		(struct exynos4_gpio_part2
 *)samsung_get_base_gpio_part2();
-	int err;
+	int err, err_sd = 0;

I think that the err_sd is not needed here. Please use the err as is was at the original code.

Quoted 12 lines
board/samsung/trats/trats.c +1 -2
 	/* eMMC_EN: SD_0_CDn: GPK0[2] Output High */
 	s5p_gpio_direction_output(&gpio->k0, 2, 1);
@@ -438,14 +458,20 @@ int board_mmc_init(bd_t *bis)
 	 * GPX3[4] T-flash detect pin
 	 */
 	if (!s5p_gpio_get_value(&gpio->x3, 4)) {
-		err = exynos_pinmux_config(PERIPH_ID_SDMMC2,
 PINMUX_FLAG_NONE);
-		if (err)
+		err_sd = exynos_pinmux_config(PERIPH_ID_SDMMC2,
 PINMUX_FLAG_NONE);

board/samsung/trats/trats.c int board_mmc_init(bd_t *bis) · line 471

Quoted 10 lines
board/samsung/trats/trats.c +7 -2
+		if (err_sd)
 			debug("SDMMC2 not configured\n");
-		else
-			err = s5p_mmc_init(2, 4);
+		else {
+			if (!sd_ldo_control(1)) {
+				err_sd = s5p_mmc_init(2, 4);
+				if (err_sd) {
+					sd_ldo_control(0);
+				}

Parenthesis with this if aren't needed.

Quoted 9 lines
board/samsung/trats/trats.c +3 -1
+			}
+		}
 	}
 
-	return err;
+	return err & err_sd;
 }

#endif

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
#2 lore raw

PATCH 1/1 arm: trats: add the sd-card power control function.

Hi Lukasz,

Thanks for your comments.

Quoted 21 lines · Lukasz Majewski

Hi Jaehoon,

Quoted 19 lines

To use the sd-card, VTF_2.8V will be enabled.
Before this patch, VTF_2.8V is always disabled.(card can't initialize.) When card is detected, SD-card power will enable with sd_ldo_control().

---
 board/samsung/trats/trats.c |   38

++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-)

board/samsung/trats/trats.c +0 -0
index 7f61d17..9b6dd12 100644
@@ -408,11 +408,31 @@ int checkboard(void)
 #endif
 
Quoted 10 lines

board/samsung/trats/trats.c int checkboard(void) · line 417

Quoted 8 lines
board/samsung/trats/trats.c +7 -0
 #ifdef CONFIG_GENERIC_MMC
+static int sd_ldo_control(int on)
+{
+	struct pmic *p = pmic_get("MAX8997_PMIC");
+	u32 val = 0;
+	int ret = 0;
+	if (pmic_probe(p))
+		return -1;

Maybe -1 -> -ENODEV

Will fix..

Quoted 5 lines

board/samsung/trats/trats.c int checkboard(void) · line 420

Quoted 4 lines
board/samsung/trats/trats.c +3 -0
+
+	/* LDO17 VTF: 2.8V */
+	val = max8997_reg_ldo(2800000) | (on? EN_LDO : DIS_LDO);
                                          ^^^ on ?

Will fix

Quoted 2 lines

board/samsung/trats/trats.c int checkboard(void) · line 421

Quoted 1 line
board/samsung/trats/trats.c +1 -0
+	ret |= pmic_reg_write(p, MAX8997_REG_LDO17CTRL, val);
	^^^^^ ret = 

Will fix.

Quoted 5 lines

board/samsung/trats/trats.c int checkboard(void) · line 424

Quoted 3 lines
board/samsung/trats/trats.c +3 -0
+
+	if (ret) {
+		puts("MAX8997 SD setting error!\n");

Please use error() instead of puts()

Using error().

Quoted 17 lines
Quoted 4 lines
board/samsung/trats/trats.c +3 -0
+		return -1;
+	}
+

board/samsung/trats/trats.c int checkboard(void) · line 435

Quoted 10 lines
board/samsung/trats/trats.c +4 -1
+	return 0;
+}
+
 int board_mmc_init(bd_t *bis)
 {
 	struct exynos4_gpio_part2 *gpio =
 		(struct exynos4_gpio_part2
 *)samsung_get_base_gpio_part2();
-	int err;
+	int err, err_sd = 0;

I think that the err_sd is not needed here. Please use the err as is was at the original code.

As like the goni, I think sd_err needs herre.
We need to consider the cases when eMMC is intiailzed and SD-card is failed. If SD-card is failed, then it's always retunred "Fail", although eMMC is initialized. how about?
After replying your, i will send the fixing patch.

Best Regards,
Jaehoon Chung

Quoted 36 lines
Quoted 13 lines
board/samsung/trats/trats.c +1 -2
 	/* eMMC_EN: SD_0_CDn: GPK0[2] Output High */
 	s5p_gpio_direction_output(&gpio->k0, 2, 1);
@@ -438,14 +458,20 @@ int board_mmc_init(bd_t *bis)
 	 * GPX3[4] T-flash detect pin
 	 */
 	if (!s5p_gpio_get_value(&gpio->x3, 4)) {
-		err = exynos_pinmux_config(PERIPH_ID_SDMMC2,
 PINMUX_FLAG_NONE);
-		if (err)
+		err_sd = exynos_pinmux_config(PERIPH_ID_SDMMC2,
 PINMUX_FLAG_NONE);

board/samsung/trats/trats.c int board_mmc_init(bd_t *bis) · line 471

Quoted 10 lines
board/samsung/trats/trats.c +7 -2
+		if (err_sd)
 			debug("SDMMC2 not configured\n");
-		else
-			err = s5p_mmc_init(2, 4);
+		else {
+			if (!sd_ldo_control(1)) {
+				err_sd = s5p_mmc_init(2, 4);
+				if (err_sd) {
+					sd_ldo_control(0);
+				}

Parenthesis with this if aren't needed.

Quoted 9 lines
board/samsung/trats/trats.c +3 -1
+			}
+		}
 	}
 
-	return err;
+	return err & err_sd;
 }

#endif

#3 lore raw

PATCH 1/1 arm: trats: add the sd-card power control function.

Hi Jaehoon,

Quoted 69 lines

Hi Lukasz,

Thanks for your comments.

Quoted 21 lines · Lukasz Majewski

Hi Jaehoon,

Quoted 19 lines

To use the sd-card, VTF_2.8V will be enabled.
Before this patch, VTF_2.8V is always disabled.(card can't initialize.) When card is detected, SD-card power will enable with sd_ldo_control().

---
 board/samsung/trats/trats.c |   38

++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-)

(quoted diff) +0 -0

b/board/samsung/trats/trats.c index 7f61d17..9b6dd12 100644

board/samsung/trats/trats.c +0 -0
@@ -408,11 +408,31 @@ int checkboard(void)
 #endif
 
Quoted 10 lines

board/samsung/trats/trats.c int checkboard(void) · line 417

Quoted 8 lines
board/samsung/trats/trats.c +7 -0
 #ifdef CONFIG_GENERIC_MMC
+static int sd_ldo_control(int on)
+{
+	struct pmic *p = pmic_get("MAX8997_PMIC");
+	u32 val = 0;
+	int ret = 0;
+	if (pmic_probe(p))
+		return -1;

Maybe -1 -> -ENODEV

Will fix..

Quoted 5 lines

board/samsung/trats/trats.c int checkboard(void) · line 420

Quoted 4 lines
board/samsung/trats/trats.c +3 -0
+
+	/* LDO17 VTF: 2.8V */
+	val = max8997_reg_ldo(2800000) | (on? EN_LDO : DIS_LDO);
                                          ^^^ on ?

Will fix

Quoted 2 lines

board/samsung/trats/trats.c int checkboard(void) · line 421

Quoted 1 line
board/samsung/trats/trats.c +1 -0
+	ret |= pmic_reg_write(p, MAX8997_REG_LDO17CTRL, val);
	^^^^^ ret = 

Will fix.

Quoted 5 lines

board/samsung/trats/trats.c int checkboard(void) · line 424

Quoted 3 lines
board/samsung/trats/trats.c +3 -0
+
+	if (ret) {
+		puts("MAX8997 SD setting error!\n");

Please use error() instead of puts()

Using error().

Quoted 17 lines
Quoted 4 lines
board/samsung/trats/trats.c +3 -0
+		return -1;
+	}
+

board/samsung/trats/trats.c int checkboard(void) · line 435

Quoted 10 lines
board/samsung/trats/trats.c +4 -1
+	return 0;
+}
+
 int board_mmc_init(bd_t *bis)
 {
 	struct exynos4_gpio_part2 *gpio =
 		(struct exynos4_gpio_part2
 *)samsung_get_base_gpio_part2();
-	int err;
+	int err, err_sd = 0;

I think that the err_sd is not needed here. Please use the err as is was at the original code.

Quoted 4 lines

As like the goni, I think sd_err needs herre.
We need to consider the cases when eMMC is intiailzed and SD-card is failed. If SD-card is failed, then it's always retunred "Fail", although eMMC is initialized. how about?

I think that it is perfectly correct when we insert SD card (which is signaled by change of card detect pin - X3[4]) and when we fail to initialize it to display the error message and pass the error code out of the function.

Then user can read the error cause from the console and perform hard reset with SD card removed.

Quoted 29 lines

After replying your, i will send the fixing patch.

Best Regards,
Jaehoon Chung

Quoted 25 lines
Quoted 13 lines
board/samsung/trats/trats.c +1 -2
 	/* eMMC_EN: SD_0_CDn: GPK0[2] Output High */
 	s5p_gpio_direction_output(&gpio->k0, 2, 1);
@@ -438,14 +458,20 @@ int board_mmc_init(bd_t *bis)
 	 * GPX3[4] T-flash detect pin
 	 */
 	if (!s5p_gpio_get_value(&gpio->x3, 4)) {
-		err = exynos_pinmux_config(PERIPH_ID_SDMMC2,
 PINMUX_FLAG_NONE);
-		if (err)
+		err_sd = exynos_pinmux_config(PERIPH_ID_SDMMC2,
 PINMUX_FLAG_NONE);

board/samsung/trats/trats.c int board_mmc_init(bd_t *bis) · line 471

Quoted 10 lines
board/samsung/trats/trats.c +7 -2
+		if (err_sd)
 			debug("SDMMC2 not configured\n");
-		else
-			err = s5p_mmc_init(2, 4);
+		else {
+			if (!sd_ldo_control(1)) {
+				err_sd = s5p_mmc_init(2, 4);
+				if (err_sd) {
+					sd_ldo_control(0);
+				}

Parenthesis with this if aren't
needed.

Quoted 6 lines
Quoted 6 lines

board/samsung/trats/trats.c int board_mmc_init(bd_t *bis) · line 474

Quoted 6 lines
board/samsung/trats/trats.c +3 -1
+			}
+		}
 	}
 
-	return err;
+	return err & err_sd;

To be honest I'm frowned upon when errors are ANDed. In my opinion they shall be ORed together.

So I think that for the trats.c we only need to do the following:

 	if (!s5p_gpio_get_value(&gpio->x3, 4)) {
	err |= exynos_pinmux_config(PERIPH_ID_SDMMC2, PINMUX_FLAG_NONE);
		if (err) {
 			debug("SDMMC2 not configured\n");
		} else {
			if (!sd_ldo_control(1)) {
				err |= s5p_mmc_init(2, 4);
				if (err) {
					sd_ldo_control(0);
					error("SD catd init failed\
					- remove it\n");
				}
			}
		}

}

	return err;

Please consider following scenarios:

1. eMMC OK, card present and broken -> print informative error message (to recover user will remove the card)

2. eMMC OK + card inserted and init OK = no problem

3. eMMC OK + card not inserted = no problem

4. eMMC initialization broken + card inserted and init OK - we will not boot the device from eMMC, so we will not be able to use SD card at u-boot.

Please correct me if I'm wrong and/or I've overlooked some useful scenario for you.

Best regards,
Lukasz Majewski
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20131103/95b38749/attachment.pgp>

#4 lore raw

PATCH 1/1 arm: trats: add the sd-card power control function.

Hi, Lukasz,

Quoted 152 lines · Lukasz Majewski

Hi Jaehoon,

Quoted 69 lines

Hi Lukasz,

Thanks for your comments.

Quoted 21 lines · Lukasz Majewski

Hi Jaehoon,

Quoted 19 lines

To use the sd-card, VTF_2.8V will be enabled.
Before this patch, VTF_2.8V is always disabled.(card can't initialize.) When card is detected, SD-card power will enable with sd_ldo_control().

---
 board/samsung/trats/trats.c |   38

++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-)

(quoted diff) +0 -0

b/board/samsung/trats/trats.c index 7f61d17..9b6dd12 100644

board/samsung/trats/trats.c +0 -0
@@ -408,11 +408,31 @@ int checkboard(void)
 #endif
 
Quoted 10 lines

board/samsung/trats/trats.c int checkboard(void) · line 417

Quoted 8 lines
board/samsung/trats/trats.c +7 -0
 #ifdef CONFIG_GENERIC_MMC
+static int sd_ldo_control(int on)
+{
+	struct pmic *p = pmic_get("MAX8997_PMIC");
+	u32 val = 0;
+	int ret = 0;
+	if (pmic_probe(p))
+		return -1;

Maybe -1 -> -ENODEV

Will fix..

Quoted 5 lines

board/samsung/trats/trats.c int checkboard(void) · line 420

Quoted 4 lines
board/samsung/trats/trats.c +3 -0
+
+	/* LDO17 VTF: 2.8V */
+	val = max8997_reg_ldo(2800000) | (on? EN_LDO : DIS_LDO);
                                          ^^^ on ?

Will fix

Quoted 2 lines

board/samsung/trats/trats.c int checkboard(void) · line 421

Quoted 1 line
board/samsung/trats/trats.c +1 -0
+	ret |= pmic_reg_write(p, MAX8997_REG_LDO17CTRL, val);
	^^^^^ ret = 

Will fix.

Quoted 5 lines

board/samsung/trats/trats.c int checkboard(void) · line 424

Quoted 3 lines
board/samsung/trats/trats.c +3 -0
+
+	if (ret) {
+		puts("MAX8997 SD setting error!\n");

Please use error() instead of puts()

Using error().

Quoted 17 lines
Quoted 4 lines
board/samsung/trats/trats.c +3 -0
+		return -1;
+	}
+

board/samsung/trats/trats.c int checkboard(void) · line 435

Quoted 10 lines
board/samsung/trats/trats.c +4 -1
+	return 0;
+}
+
 int board_mmc_init(bd_t *bis)
 {
 	struct exynos4_gpio_part2 *gpio =
 		(struct exynos4_gpio_part2
 *)samsung_get_base_gpio_part2();
-	int err;
+	int err, err_sd = 0;

I think that the err_sd is not needed here. Please use the err as is was at the original code.

Quoted 4 lines

As like the goni, I think sd_err needs herre.
We need to consider the cases when eMMC is intiailzed and SD-card is failed. If SD-card is failed, then it's always retunred "Fail", although eMMC is initialized. how about?

I think that it is perfectly correct when we insert SD card (which is signaled by change of card detect pin - X3[4]) and when we fail to initialize it to display the error message and pass the error code out of the function.

Then user can read the error cause from the console and perform hard reset with SD card removed.

Quoted 29 lines

After replying your, i will send the fixing patch.

Best Regards,
Jaehoon Chung

Quoted 25 lines
Quoted 13 lines
board/samsung/trats/trats.c +1 -2
 	/* eMMC_EN: SD_0_CDn: GPK0[2] Output High */
 	s5p_gpio_direction_output(&gpio->k0, 2, 1);
@@ -438,14 +458,20 @@ int board_mmc_init(bd_t *bis)
 	 * GPX3[4] T-flash detect pin
 	 */
 	if (!s5p_gpio_get_value(&gpio->x3, 4)) {
-		err = exynos_pinmux_config(PERIPH_ID_SDMMC2,
 PINMUX_FLAG_NONE);
-		if (err)
+		err_sd = exynos_pinmux_config(PERIPH_ID_SDMMC2,
 PINMUX_FLAG_NONE);

board/samsung/trats/trats.c int board_mmc_init(bd_t *bis) · line 471

Quoted 10 lines
board/samsung/trats/trats.c +7 -2
+		if (err_sd)
 			debug("SDMMC2 not configured\n");
-		else
-			err = s5p_mmc_init(2, 4);
+		else {
+			if (!sd_ldo_control(1)) {
+				err_sd = s5p_mmc_init(2, 4);
+				if (err_sd) {
+					sd_ldo_control(0);
+				}

Parenthesis with this if aren't
needed.

Quoted 6 lines
Quoted 6 lines

board/samsung/trats/trats.c int board_mmc_init(bd_t *bis) · line 474

Quoted 6 lines
board/samsung/trats/trats.c +3 -1
+			}
+		}
 	}
 
-	return err;
+	return err & err_sd;

To be honest I'm frowned upon when errors are ANDed. In my opinion they shall be ORed together.

So I think that for the trats.c we only need to do the following:

 	if (!s5p_gpio_get_value(&gpio->x3, 4)) {
	err |= exynos_pinmux_config(PERIPH_ID_SDMMC2, PINMUX_FLAG_NONE);
		if (err) {
 			debug("SDMMC2 not configured\n");
		} else {
			if (!sd_ldo_control(1)) {
				err |= s5p_mmc_init(2, 4);
				if (err) {
					sd_ldo_control(0);
					error("SD catd init failed\
					- remove it\n");
				}
			}
		}

}

	return err;

Please consider following scenarios:

1. eMMC OK, card present and broken -> print informative error message (to recover user will remove the card)

2. eMMC OK + card inserted and init OK = no problem

Quoted 8 lines

3. eMMC OK + card not inserted = no problem

4. eMMC initialization broken + card inserted and init OK - we will not boot the device from eMMC, so we will not be able to use SD card at u-boot.

Please correct me if I'm wrong and/or I've overlooked some useful scenario for you.

As your opinion, I will test and rework the patch.

Best Regards,
Jaehoon Chung

Quoted 4 lines

Best regards,
Lukasz Majewski