Patchwork [U-Boot,4/6] mxs: mmc: Allow overriding default card detect implementation

login
register
mail settings
Submitter Marek Vasut
Date Jan. 23, 2013, 1:01 a.m.
Message ID <1358902865-20475-4-git-send-email-marex@denx.de>
Download mbox | patch
Permalink /patch/214704/
State Awaiting Upstream
Delegated to: Stefano Babic
Headers show

Comments

Marek Vasut - Jan. 23, 2013, 1:01 a.m.
Some MXS based boards do not implement the card-detect signal. Allow
user to specify alternate card-detect implementation.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Otavio Salvador <otavio@ossystems.com.br>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
---
 arch/arm/include/asm/arch-mxs/sys_proto.h |    2 +-
 board/bluegiga/apx4devkit/apx4devkit.c    |    2 +-
 board/denx/m28evk/m28evk.c                |    2 +-
 board/freescale/mx28evk/mx28evk.c         |    2 +-
 board/schulercontrol/sc_sps_1/sc_sps_1.c  |    2 +-
 drivers/mmc/mxsmmc.c                      |   16 ++++++++++++++--
 6 files changed, 19 insertions(+), 7 deletions(-)
Stefano Babic - Jan. 24, 2013, 6:27 p.m.
On 23/01/2013 02:01, Marek Vasut wrote:
> Some MXS based boards do not implement the card-detect signal. Allow
> user to specify alternate card-detect implementation.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Otavio Salvador <otavio@ossystems.com.br>
> Cc: Fabio Estevam <fabio.estevam@freescale.com>
> Cc: Stefano Babic <sbabic@denx.de>
> ---
>  arch/arm/include/asm/arch-mxs/sys_proto.h |    2 +-
>  board/bluegiga/apx4devkit/apx4devkit.c    |    2 +-
>  board/denx/m28evk/m28evk.c                |    2 +-
>  board/freescale/mx28evk/mx28evk.c         |    2 +-
>  board/schulercontrol/sc_sps_1/sc_sps_1.c  |    2 +-
>  drivers/mmc/mxsmmc.c                      |   16 ++++++++++++++--
>  6 files changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/arm/include/asm/arch-mxs/sys_proto.h b/arch/arm/include/asm/arch-mxs/sys_proto.h
> index 8aaf196..5bafde5 100644
> --- a/arch/arm/include/asm/arch-mxs/sys_proto.h
> +++ b/arch/arm/include/asm/arch-mxs/sys_proto.h
> @@ -31,7 +31,7 @@ int mxs_wait_mask_clr(struct mxs_register_32 *reg,
>  		       uint32_t mask,
>  		       unsigned int timeout);
>  
> -int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int));
> +int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int));
>  
>  #ifdef CONFIG_SPL_BUILD
>  
> diff --git a/board/bluegiga/apx4devkit/apx4devkit.c b/board/bluegiga/apx4devkit/apx4devkit.c
> index 029b973..5927693 100644
> --- a/board/bluegiga/apx4devkit/apx4devkit.c
> +++ b/board/bluegiga/apx4devkit/apx4devkit.c
> @@ -69,7 +69,7 @@ int board_init(void)
>  #ifdef CONFIG_CMD_MMC
>  int board_mmc_init(bd_t *bis)
>  {
> -	return mxsmmc_initialize(bis, 0, NULL);
> +	return mxsmmc_initialize(bis, 0, NULL, NULL);

I see, but it seems to me that mxs is doing different as other SOCs. If
there is nothing to set, cpu_mmc_init() should be used, dropping
board_mmc_init(). And we implement board_mmc_init() only for boards that
really need it, not for all.

Best regards,
Stefano Babic
Marek Vasut - Jan. 24, 2013, 6:29 p.m.
Dear Stefano Babic,

> On 23/01/2013 02:01, Marek Vasut wrote:
> > Some MXS based boards do not implement the card-detect signal. Allow
> > user to specify alternate card-detect implementation.
> > 
> > Signed-off-by: Marek Vasut <marex@denx.de>
> > Cc: Otavio Salvador <otavio@ossystems.com.br>
> > Cc: Fabio Estevam <fabio.estevam@freescale.com>
> > Cc: Stefano Babic <sbabic@denx.de>
> > ---
> > 
> >  arch/arm/include/asm/arch-mxs/sys_proto.h |    2 +-
> >  board/bluegiga/apx4devkit/apx4devkit.c    |    2 +-
> >  board/denx/m28evk/m28evk.c                |    2 +-
> >  board/freescale/mx28evk/mx28evk.c         |    2 +-
> >  board/schulercontrol/sc_sps_1/sc_sps_1.c  |    2 +-
> >  drivers/mmc/mxsmmc.c                      |   16 ++++++++++++++--
> >  6 files changed, 19 insertions(+), 7 deletions(-)
> > 
> > diff --git a/arch/arm/include/asm/arch-mxs/sys_proto.h
> > b/arch/arm/include/asm/arch-mxs/sys_proto.h index 8aaf196..5bafde5
> > 100644
> > --- a/arch/arm/include/asm/arch-mxs/sys_proto.h
> > +++ b/arch/arm/include/asm/arch-mxs/sys_proto.h
> > @@ -31,7 +31,7 @@ int mxs_wait_mask_clr(struct mxs_register_32 *reg,
> > 
> >  		       uint32_t mask,
> >  		       unsigned int timeout);
> > 
> > -int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int));
> > +int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int
> > (*cd)(int));
> > 
> >  #ifdef CONFIG_SPL_BUILD
> > 
> > diff --git a/board/bluegiga/apx4devkit/apx4devkit.c
> > b/board/bluegiga/apx4devkit/apx4devkit.c index 029b973..5927693 100644
> > --- a/board/bluegiga/apx4devkit/apx4devkit.c
> > +++ b/board/bluegiga/apx4devkit/apx4devkit.c
> > @@ -69,7 +69,7 @@ int board_init(void)
> > 
> >  #ifdef CONFIG_CMD_MMC
> >  int board_mmc_init(bd_t *bis)
> >  {
> > 
> > -	return mxsmmc_initialize(bis, 0, NULL);
> > +	return mxsmmc_initialize(bis, 0, NULL, NULL);
> 
> I see, but it seems to me that mxs is doing different as other SOCs. If
> there is nothing to set, cpu_mmc_init() should be used, dropping
> board_mmc_init(). And we implement board_mmc_init() only for boards that
> really need it, not for all.

That's also an option ... do you want subsequent patch or respin of the series?

Best regards,
Marek Vasut
Stefano Babic - Jan. 24, 2013, 6:33 p.m.
On 24/01/2013 19:29, Marek Vasut wrote:

> 
> That's also an option ... do you want subsequent patch or respin of the series?

If I can choose, I prefer a respin of series, but I will surely not
block the patchset if you send subsequent patches...

Best regards,
Stefano Babic
Marek Vasut - Jan. 24, 2013, 6:34 p.m.
Dear Stefano Babic,
[...]

> > > diff --git a/board/bluegiga/apx4devkit/apx4devkit.c
> > > b/board/bluegiga/apx4devkit/apx4devkit.c index 029b973..5927693 100644
> > > --- a/board/bluegiga/apx4devkit/apx4devkit.c
> > > +++ b/board/bluegiga/apx4devkit/apx4devkit.c
> > > @@ -69,7 +69,7 @@ int board_init(void)
> > > 
> > >  #ifdef CONFIG_CMD_MMC
> > >  int board_mmc_init(bd_t *bis)
> > >  {
> > > 
> > > -	return mxsmmc_initialize(bis, 0, NULL);
> > > +	return mxsmmc_initialize(bis, 0, NULL, NULL);
> > 
> > I see, but it seems to me that mxs is doing different as other SOCs. If
> > there is nothing to set, cpu_mmc_init() should be used, dropping
> > board_mmc_init(). And we implement board_mmc_init() only for boards that
> > really need it, not for all.
> 
> That's also an option ... do you want subsequent patch or respin of the
> series?

Actually, check how it's distributed:

$ git grep mxsmmc_initialize board | sed "s@.*/@@"
apx4devkit.c:   return mxsmmc_initialize(bis, 0, NULL, NULL);
m28evk.c:       return mxsmmc_initialize(bis, 0, m28_mmc_wp, NULL);
mx28evk.c:      return mxsmmc_initialize(bis, 0, mx28evk_mmc_wp, NULL);
mx23_olinuxino.c:       return mxsmmc_initialize(bis, 0, NULL, mx23_olx_mmc_cd);
sc_sps_1.c:     return mxsmmc_initialize(bis, 0, NULL, NULL);

We have quite a bit of variance there. I wonder if using cpu_mmc_init() is worth 
it.

Best regards,
Marek Vasut
Marek Vasut - Jan. 24, 2013, 6:39 p.m.
Dear Stefano Babic,

> On 24/01/2013 19:29, Marek Vasut wrote:
> > That's also an option ... do you want subsequent patch or respin of the
> > series?
> 
> If I can choose, I prefer a respin of series, but I will surely not
> block the patchset if you send subsequent patches...

No, scrap this. See my other email please.

Best regards,
Marek Vasut
Stefano Babic - Jan. 28, 2013, 5:30 a.m.
On 24/01/2013 19:34, Marek Vasut wrote:

>> That's also an option ... do you want subsequent patch or respin of the
>> series?
> 
> Actually, check how it's distributed:
> 
> $ git grep mxsmmc_initialize board | sed "s@.*/@@"
> apx4devkit.c:   return mxsmmc_initialize(bis, 0, NULL, NULL);
> m28evk.c:       return mxsmmc_initialize(bis, 0, m28_mmc_wp, NULL);
> mx28evk.c:      return mxsmmc_initialize(bis, 0, mx28evk_mmc_wp, NULL);
> mx23_olinuxino.c:       return mxsmmc_initialize(bis, 0, NULL, mx23_olx_mmc_cd);
> sc_sps_1.c:     return mxsmmc_initialize(bis, 0, NULL, NULL);
> 
> We have quite a bit of variance there. I wonder if using cpu_mmc_init() is worth 
> it.

I see. Ok, then let's the things as they are.

Regards,
Stefano Babic

Patch

diff --git a/arch/arm/include/asm/arch-mxs/sys_proto.h b/arch/arm/include/asm/arch-mxs/sys_proto.h
index 8aaf196..5bafde5 100644
--- a/arch/arm/include/asm/arch-mxs/sys_proto.h
+++ b/arch/arm/include/asm/arch-mxs/sys_proto.h
@@ -31,7 +31,7 @@  int mxs_wait_mask_clr(struct mxs_register_32 *reg,
 		       uint32_t mask,
 		       unsigned int timeout);
 
-int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int));
+int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int));
 
 #ifdef CONFIG_SPL_BUILD
 
diff --git a/board/bluegiga/apx4devkit/apx4devkit.c b/board/bluegiga/apx4devkit/apx4devkit.c
index 029b973..5927693 100644
--- a/board/bluegiga/apx4devkit/apx4devkit.c
+++ b/board/bluegiga/apx4devkit/apx4devkit.c
@@ -69,7 +69,7 @@  int board_init(void)
 #ifdef CONFIG_CMD_MMC
 int board_mmc_init(bd_t *bis)
 {
-	return mxsmmc_initialize(bis, 0, NULL);
+	return mxsmmc_initialize(bis, 0, NULL, NULL);
 }
 #endif
 
diff --git a/board/denx/m28evk/m28evk.c b/board/denx/m28evk/m28evk.c
index 26f31d6..d93efaf 100644
--- a/board/denx/m28evk/m28evk.c
+++ b/board/denx/m28evk/m28evk.c
@@ -93,7 +93,7 @@  int board_mmc_init(bd_t *bis)
 	/* Turn on the power to the card. */
 	gpio_direction_output(MX28_PAD_PWM3__GPIO_3_28, 0);
 
-	return mxsmmc_initialize(bis, 0, m28_mmc_wp);
+	return mxsmmc_initialize(bis, 0, m28_mmc_wp, NULL);
 }
 #endif
 
diff --git a/board/freescale/mx28evk/mx28evk.c b/board/freescale/mx28evk/mx28evk.c
index ad66f29..de7231b 100644
--- a/board/freescale/mx28evk/mx28evk.c
+++ b/board/freescale/mx28evk/mx28evk.c
@@ -94,7 +94,7 @@  int board_mmc_init(bd_t *bis)
 	/* Configure MMC0 Power Enable */
 	gpio_direction_output(MX28_PAD_PWM3__GPIO_3_28, 0);
 
-	return mxsmmc_initialize(bis, 0, mx28evk_mmc_wp);
+	return mxsmmc_initialize(bis, 0, mx28evk_mmc_wp, NULL);
 }
 #endif
 
diff --git a/board/schulercontrol/sc_sps_1/sc_sps_1.c b/board/schulercontrol/sc_sps_1/sc_sps_1.c
index fac7e30..8138237 100644
--- a/board/schulercontrol/sc_sps_1/sc_sps_1.c
+++ b/board/schulercontrol/sc_sps_1/sc_sps_1.c
@@ -78,7 +78,7 @@  int dram_init(void)
 #ifdef	CONFIG_CMD_MMC
 int board_mmc_init(bd_t *bis)
 {
-	return mxsmmc_initialize(bis, 0, NULL);
+	return mxsmmc_initialize(bis, 0, NULL, NULL);
 }
 #endif
 
diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c
index 9d71202..023dbd5 100644
--- a/drivers/mmc/mxsmmc.c
+++ b/drivers/mmc/mxsmmc.c
@@ -49,12 +49,23 @@  struct mxsmmc_priv {
 	struct mxs_ssp_regs	*regs;
 	uint32_t		buswidth;
 	int			(*mmc_is_wp)(int);
+	int			(*mmc_cd)(int);
 	struct mxs_dma_desc	*desc;
 };
 
 #define	MXSMMC_MAX_TIMEOUT	10000
 #define MXSMMC_SMALL_TRANSFER	512
 
+static int mxsmmc_cd(struct mxsmmc_priv *priv)
+{
+	struct mxs_ssp_regs *ssp_regs = priv->regs;
+
+	if (priv->mmc_cd)
+		return priv->mmc_cd(priv->id);
+
+	return !(readl(&ssp_regs->hw_ssp_status) & SSP_STATUS_CARD_DETECT);
+}
+
 static int mxsmmc_send_cmd_pio(struct mxsmmc_priv *priv, struct mmc_data *data)
 {
 	struct mxs_ssp_regs *ssp_regs = priv->regs;
@@ -166,7 +177,7 @@  mxsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 	}
 
 	/* See if card is present */
-	if (readl(&ssp_regs->hw_ssp_status) & SSP_STATUS_CARD_DETECT) {
+	if (!mxsmmc_cd(priv)) {
 		printf("MMC%d: No card detected!\n", mmc->block_dev.dev);
 		return NO_CARD_ERR;
 	}
@@ -357,7 +368,7 @@  static int mxsmmc_init(struct mmc *mmc)
 	return 0;
 }
 
-int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int))
+int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int))
 {
 	struct mmc *mmc = NULL;
 	struct mxsmmc_priv *priv = NULL;
@@ -395,6 +406,7 @@  int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int))
 		return ret;
 
 	priv->mmc_is_wp = wp;
+	priv->mmc_cd = cd;
 	priv->id = id;
 	priv->regs = mxs_ssp_regs_by_bus(id);