[PATCH 3/3] MMC compatibility fix - OCR mask

From: Pierre Ossman
Date: Sat Sep 18 2004 - 05:06:06 EST


This patch avoids using a emtpy OCR mask for the initial power up. Since some cards do not like a one bit-mask a routine has been added which grows the mask to three bits (one extra bit on each side) if necessary.

Index: linux-wbsd/drivers/mmc/mmc.c
===================================================================
--- linux-wbsd/drivers/mmc/mmc.c (revision 63)
+++ linux-wbsd/drivers/mmc/mmc.c (revision 64)
@@ -300,6 +300,31 @@
return ocr;
}

+/*
+ * Calculate a OCR mask to use for initial scanning.
+ * All zeroes and all ones cannot be used with some cards.
+ * Just on bit cannot be used either so extend the OCR
+ * if needed.
+ */
+
+static u32 mmc_select_scan_ocr(struct mmc_host *host)
+{
+ u32 ocr;
+
+ ocr = host->ocr_avail;
+
+ /* Check if we have more than one bit */
+ if (ocr & (ocr << 1))
+ return ocr;
+ if (ocr & (ocr >> 1))
+ return ocr;
+
+ /* Extend the mask to surrounding bits */
+ ocr |= (ocr << 1) | (ocr >> 1);
+
+ return ocr;
+}
+
static void mmc_decode_cid(struct mmc_cid *cid, u32 *resp)
{
memset(cid, 0, sizeof(struct mmc_cid));
@@ -589,7 +614,9 @@

mmc_power_up(host);

- err = mmc_send_op_cond(host, 0, &ocr);
+ ocr = mmc_select_scan_ocr(host);
+
+ err = mmc_send_op_cond(host, ocr, &ocr);
if (err != MMC_ERR_NONE)
return;