Skip to contentSkip to conversation

imx: mx6quq7: add sd card detection

PATCH New Julien Corjon 3 participants 7 messages Feb 5, 2016 – Feb 21, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 imx: mx6quq7: add sd card detection

Add board_mmc_getcd function and declare CD_GPIO for SDCard.

---
 board/seco/mx6quq7/mx6quq7.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
board/seco/mx6quq7/mx6quq7.c +22 -5
index ea1d4b8..d70c6bc 100644
@@ -91,11 +91,30 @@ int board_eth_init(bd_t *bis)
 	return ret;
 }
 
+#define USDHC4_CD_GPIO		IMX_GPIO_NR(2, 6)
+
 static struct fsl_esdhc_cfg usdhc_cfg[2] = {
-	{USDHC3_BASE_ADDR},
-	{USDHC2_BASE_ADDR},
+	{USDHC3_BASE_ADDR, 0, 4},
+	{USDHC4_BASE_ADDR, 0, 4},
 };
 
+int board_mmc_getcd(struct mmc *mmc)
+{
+        struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
+        int ret = 0;
+
+        switch (cfg->esdhc_base) {
+	case USDHC3_BASE_ADDR:
+		ret = 1; /* Assume eMMC is always present */
+		break;
+        case USDHC4_BASE_ADDR:
+                ret = !gpio_get_value(USDHC4_CD_GPIO);
+                break;
+        }
+
+        return ret;
+}
+
 int board_mmc_init(bd_t *bis)
 {
 	u32 index = 0;
@@ -112,14 +131,12 @@ int board_mmc_init(bd_t *bis)
 		case 0:
 			seco_mx6_setup_usdhc_iomux(3);
 			usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
-			usdhc_cfg[0].max_bus_width = 4;
 			break;
 		case 1:
 			seco_mx6_setup_usdhc_iomux(4);
+			gpio_direction_input(USDHC4_CD_GPIO);
 			usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
-			usdhc_cfg[1].max_bus_width = 4;
 			break;
-
 		default:
 			printf("Warning: %d exceed maximum number of SD ports %d\n",
 			       index + 1, CONFIG_SYS_FSL_USDHC_NUM);
Signature · 1 line
2.5.0
#1 lore raw

PATCH 1/1 imx: mx6quq7: add sd card detection

Hi Julien,

Quoted 2 lines · On Fri, 5 Feb 2016 13:41:29 +0100 Julien Corjon <[email protected]> wrote:

Add board_mmc_getcd function and declare CD_GPIO for SDCard.

This looks good to me, but can you split the changes in 3 different patches:
1/ remove USDHC2
2/ specify max_bus_width directly in usdhc_cfg static definition
instead of tweaking it in the board_mmc_init() function.
3/ add USDHC4 + MMC detect

Quoted 25 lines
---
 board/seco/mx6quq7/mx6quq7.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
board/seco/mx6quq7/mx6quq7.c +6 -2
index ea1d4b8..d70c6bc 100644
@@ -91,11 +91,30 @@ int board_eth_init(bd_t *bis)
 	return ret;
 }
 
+#define USDHC4_CD_GPIO		IMX_GPIO_NR(2, 6)
+
 static struct fsl_esdhc_cfg usdhc_cfg[2] = {
-	{USDHC3_BASE_ADDR},
-	{USDHC2_BASE_ADDR},
+	{USDHC3_BASE_ADDR, 0, 4},
+	{USDHC4_BASE_ADDR, 0, 4},
 };
 
+int board_mmc_getcd(struct mmc *mmc)
+{

board/seco/mx6quq7/mx6quq7.c int board_eth_init(bd_t *bis) · line 112

Quoted 10 lines
board/seco/mx6quq7/mx6quq7.c +10 -0
+        struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
+        int ret = 0;
+
+        switch (cfg->esdhc_base) {
+	case USDHC3_BASE_ADDR:
+		ret = 1; /* Assume eMMC is always present */
+		break;
+        case USDHC4_BASE_ADDR:
+                ret = !gpio_get_value(USDHC4_CD_GPIO);
+                break;

Please use tabs instead of spaces (scripts/checkpatch.sh should complain about that).

Quoted 14 lines
board/seco/mx6quq7/mx6quq7.c +5 -1
+        }
+
+        return ret;
+}
+
 int board_mmc_init(bd_t *bis)
 {
 	u32 index = 0;
@@ -112,14 +131,12 @@ int board_mmc_init(bd_t *bis)
 		case 0:
 			seco_mx6_setup_usdhc_iomux(3);
 			usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
-			usdhc_cfg[0].max_bus_width = 4;
 			break;

board/seco/mx6quq7/mx6quq7.c int board_mmc_init(bd_t *bis) · line 142

Quoted 10 lines
board/seco/mx6quq7/mx6quq7.c +1 -2
 		case 1:
 			seco_mx6_setup_usdhc_iomux(4);
+			gpio_direction_input(USDHC4_CD_GPIO);
 			usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
-			usdhc_cfg[1].max_bus_width = 4;
 			break;
-
 		default:
 			printf("Warning: %d exceed maximum number of SD ports %d\n",
 			       index + 1, CONFIG_SYS_FSL_USDHC_NUM);

Thanks,

Boris

Signature · 3 lines
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#2 lore raw

PATCH v2 1/3 imx: mx6quq7: fix USDHC4 declaration

USDHC2 does not exist on mx6quq7 board, as USDHC4 was already been declared this is probably a typo.

---
v1 -> v2
- Split patch (suggested by Boris)
- Replace spaces with tab (suggested by Boris)

 board/seco/mx6quq7/mx6quq7.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/seco/mx6quq7/mx6quq7.c +1 -1
index ea1d4b8..3743a9e 100644
@@ -93,7 +93,7 @@ int board_eth_init(bd_t *bis)
 
 static struct fsl_esdhc_cfg usdhc_cfg[2] = {
 	{USDHC3_BASE_ADDR},
-	{USDHC2_BASE_ADDR},
+	{USDHC4_BASE_ADDR},
 };
 
 int board_mmc_init(bd_t *bis)
Signature · 1 line
2.5.0
#3 lore raw

PATCH v2 2/3 imx: mx6quq7: specify max_bus_witdh directly in usdhc_cfg

Specify max_bus_width directly in usdhc_cfg static definition instead of tweaking it in the board_mmc_init() function.

---
v1 -> v2
- Split patch (suggested by Boris)
- Replace spaces with tab (suggested by Boris)

 board/seco/mx6quq7/mx6quq7.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
board/seco/mx6quq7/mx6quq7.c +2 -4
index 3743a9e..89ae70d 100644
@@ -92,8 +92,8 @@ int board_eth_init(bd_t *bis)
 }
 
 static struct fsl_esdhc_cfg usdhc_cfg[2] = {
-	{USDHC3_BASE_ADDR},
-	{USDHC4_BASE_ADDR},
+	{USDHC3_BASE_ADDR, 0, 4},
+	{USDHC4_BASE_ADDR, 0, 4},
 };
 
 int board_mmc_init(bd_t *bis)
@@ -112,12 +112,10 @@ int board_mmc_init(bd_t *bis)
 		case 0:
 			seco_mx6_setup_usdhc_iomux(3);
 			usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
-			usdhc_cfg[0].max_bus_width = 4;
 			break;
 		case 1:
 			seco_mx6_setup_usdhc_iomux(4);
 			usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
-			usdhc_cfg[1].max_bus_width = 4;
 			break;
 
 		default:
Signature · 1 line
2.5.0
#4 lore raw

PATCH v2 3/3 imx: mx6quq7: add sd card detection

In reply to Julien Corjon

Add board_mmc_getcd function and declare CD_GPIO for SDCard.

---
v1 -> v2
- Split patch (suggested by Boris)
- Replace spaces with tab (suggested by Boris)

 board/seco/mx6quq7/mx6quq7.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
board/seco/mx6quq7/mx6quq7.c +19 -0
index 89ae70d..6be0b98 100644
@@ -91,11 +91,30 @@ int board_eth_init(bd_t *bis)
 	return ret;
 }
 
+#define USDHC4_CD_GPIO		IMX_GPIO_NR(2, 6)
+
 static struct fsl_esdhc_cfg usdhc_cfg[2] = {
 	{USDHC3_BASE_ADDR, 0, 4},
 	{USDHC4_BASE_ADDR, 0, 4},
 };
 
+int board_mmc_getcd(struct mmc *mmc)
+{
+	struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
+	int ret = 0;
+
+	switch (cfg->esdhc_base) {
+	case USDHC3_BASE_ADDR:
+		ret = 1; /* Assume eMMC is always present */
+		break;
+	case USDHC4_BASE_ADDR:
+		ret = !gpio_get_value(USDHC4_CD_GPIO);
+		break;
+	}
+
+	return ret;
+}
+
 int board_mmc_init(bd_t *bis)
 {
 	u32 index = 0;
Signature · 1 line
2.5.0
#5 lore raw

PATCH v2 1/3 imx: mx6quq7: fix USDHC4 declaration

In reply to Julien Corjon
Quoted 4 lines · On Fri, 5 Feb 2016 16:19:31 +0100 Julien Corjon <[email protected]> wrote:

USDHC2 does not exist on mx6quq7 board, as USDHC4 was already been declared this is probably a typo.

For the whole series:

Thanks,

Boris

Quoted 21 lines

---
v1 -> v2
- Split patch (suggested by Boris)
- Replace spaces with tab (suggested by Boris)

 board/seco/mx6quq7/mx6quq7.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/seco/mx6quq7/mx6quq7.c +1 -1
index ea1d4b8..3743a9e 100644
@@ -93,7 +93,7 @@ int board_eth_init(bd_t *bis)
 
 static struct fsl_esdhc_cfg usdhc_cfg[2] = {
 	{USDHC3_BASE_ADDR},
-	{USDHC2_BASE_ADDR},
+	{USDHC4_BASE_ADDR},
 };
 
 int board_mmc_init(bd_t *bis)
Signature · 3 lines
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#6 lore raw

PATCH v2 1/3 imx: mx6quq7: fix USDHC4 declaration

In reply to Julien Corjon
Quoted 18 lines · Julien Corjon

USDHC2 does not exist on mx6quq7 board, as USDHC4 was already been declared this is probably a typo.

---
v1 -> v2
- Split patch (suggested by Boris)
- Replace spaces with tab (suggested by Boris)

 board/seco/mx6quq7/mx6quq7.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/seco/mx6quq7/mx6quq7.c +0 -0
index ea1d4b8..3743a9e 100644

board/seco/mx6quq7/mx6quq7.c int board_eth_init(bd_t *bis) · line 99

Quoted 8 lines
board/seco/mx6quq7/mx6quq7.c +1 -1
@@ -93,7 +93,7 @@ int board_eth_init(bd_t *bis)
 
 static struct fsl_esdhc_cfg usdhc_cfg[2] = {
 	{USDHC3_BASE_ADDR},
-	{USDHC2_BASE_ADDR},
+	{USDHC4_BASE_ADDR},
 };
 
 int board_mmc_init(bd_t *bis)

Applied (whole series) to u-boot-imx, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================