On Thu, Nov 17, 2011 at 5:51 AM, Thierry Reding <thierry.red...@avionic-design.de> wrote: > Check for board-specific card detect each time an MMC/SD device is > initialized. If card detection is not implemented, this code behaves as > before and continues assuming a card is present. If no card is detected, > has_init is reset for the MMC/SD device (to force initialization next > time) and an error is returned. > > Signed-off-by: Thierry Reding <thierry.red...@avionic-design.de> > --- > drivers/mmc/mmc.c | 9 +++++++++ > 1 files changed, 9 insertions(+), 0 deletions(-) > > diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c > index 37ce6e8..d18c095 100644 > --- a/drivers/mmc/mmc.c > +++ b/drivers/mmc/mmc.c > @@ -1191,6 +1191,15 @@ block_dev_desc_t *mmc_get_dev(int dev) > int mmc_init(struct mmc *mmc) > { > int err, retry = 3; > + u8 card_detect = 0; > + > + if (board_mmc_getcd(&card_detect, mmc) == 0) {
Well, now the time has come to think about how we want this to work. As some others noted, the FSL code has been treating the cd argument to board_mmc_getcd() as a bit that is asserted low. My inclination is to change all of them to work as you have proposed (cd == 1 ==> card is detected), but I'd like input from the community. Card detection isn't so speedy that the extra inversion required is much of a factor. Are there any good arguments for keeping the meaning as ~CD? Also, to handle code like is in fsl_esdhc.c for fallback in case no board-specific code is written, I'm thinking we should use a mechanism similar to the ethernet drivers: if (board_eth_init != __def_eth_init) { if (board_eth_init(bis) < 0) printf("Board Net Initialization Failed\n"); } else if (cpu_eth_init != __def_eth_init) { if (cpu_eth_init(bis) < 0) printf("CPU Net Initialization Failed\n"); Basically, if the board_eth_init is set to something, call it. Otherwise, call the cpu_eth_init, if it exists. So we could have: int mmc_getcd(mmc, &cd) // mmc should always have been the first argument... { if (board_mmc_getcd != __def_mmc_getcd) return board_mmc_getcd(mmc, cd); else if (cpu_mmc_getcd != __def_mmc_getcd) return cpu_mmc_getcd(mmc, cd); return -1; } Open questions: 1) If we use this sort of mechanism, we don't really need the "-1 means it's not implemented" error. Perhaps we could change it to be: cd = mmc_getcd(mmc) ? 2) Should we add the ability for *drivers* to specify a card detect mechanism, and if so, where should it fit in the priority order? Most systems seem to provide GPIOs for the card detection, and even the controllers which support card detection from the device are often not always hooked up in such a way to actually *use* that support. > + if (!card_detect) { > + mmc->has_init = 0; > + printf("MMC: no card present\n"); > + return NO_CARD_ERR; > + } > + } Anyway, I liked this patch, and want to apply it, but there are some issues we need to resolve before we can apply it. Andy _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot