MMC: Extends card quicks with MMC/SD quirks matching the CID.
authorAndrei Warkentin <andreiw@motorola.com>
Sun, 13 Mar 2011 13:48:37 +0000 (08:48 -0500)
committerKen Sumrall <ksumrall@android.com>
Fri, 8 Apr 2011 00:53:27 +0000 (17:53 -0700)
The current mechanism is SDIO-only. This allows us to create
function-specific quirks, without creating messy Kconfig dependencies,
or polluting core/ with function-specific code.

Change-Id: If31a151c20a8a1fddb0774674821e9fdc4aa61a0
Signed-off-by: Andrei Warkentin <andreiw@motorola.com>
drivers/mmc/core/core.h
drivers/mmc/core/quirks.c
drivers/mmc/core/sdio.c
include/linux/mmc/card.h

index cb686b976a348bafeb69d47ab7f4cc1279d3fa49..9d9eef50e5d1976fb5d9874a00f4cf2db77c540a 100644 (file)
@@ -56,8 +56,6 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr);
 int mmc_attach_sd(struct mmc_host *host, u32 ocr);
 int mmc_attach_sdio(struct mmc_host *host, u32 ocr);
 
-void mmc_fixup_device(struct mmc_card *card);
-
 /* Module parameters */
 extern int use_spi_crc;
 extern int mmc_assume_removable;
index aa811fc5db1040547621a556fb96d736240ecd03..981c11343f457ef55336992ebff1502b4b12a29c 100644 (file)
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/mmc/card.h>
-#include <linux/mod_devicetable.h>
-
-/*
- *  The world is not perfect and supplies us with broken mmc/sdio devices.
- *  For at least a part of these bugs we need a work-around
- */
-
-struct mmc_fixup {
-       u16 vendor, device;     /* You can use SDIO_ANY_ID here of course */
-       void (*vendor_fixup)(struct mmc_card *card, int data);
-       int data;
-};
-
-/*
- * This hook just adds a quirk unconditionnally
- */
-static void __maybe_unused add_quirk(struct mmc_card *card, int data)
-{
-       card->quirks |= data;
-}
-
-/*
- * This hook just removes a quirk unconditionnally
- */
-static void __maybe_unused remove_quirk(struct mmc_card *card, int data)
-{
-       card->quirks &= ~data;
-}
 
 static const struct mmc_fixup mmc_fixup_methods[] = {
-       { 0 }
+       END_FIXUP
 };
 
-void mmc_fixup_device(struct mmc_card *card)
+void mmc_fixup_device(struct mmc_card *card,
+                     const struct mmc_fixup *table)
 {
        const struct mmc_fixup *f;
-
-       for (f = mmc_fixup_methods; f->vendor_fixup; f++) {
-               if ((f->vendor == card->cis.vendor
-                    || f->vendor == (u16) SDIO_ANY_ID) &&
-                   (f->device == card->cis.device
-                    || f->device == (u16) SDIO_ANY_ID)) {
+       u64 rev = cid_rev_card(card);
+
+       /* Non-core specific workarounds. */
+       if (!table)
+               table = mmc_fixup_methods;
+
+       for (f = table; f->vendor_fixup; f++) {
+               if ((f->manfid == CID_MANFID_ANY
+                    || f->manfid == card->cid.manfid) &&
+                   (f->oemid == CID_OEMID_ANY
+                    || f->oemid == card->cid.oemid) &&
+                   (f->name == CID_NAME_ANY
+                    || !strcmp(f->name, card->cid.prod_name)) &&
+                   (f->cis_vendor == card->cis.vendor
+                    || f->cis_vendor == (u16) SDIO_ANY_ID) &&
+                   (f->cis_device == card->cis.device
+                   || f->cis_device == (u16) SDIO_ANY_ID) &&
+                   rev >= f->rev_start &&
+                   rev <= f->rev_end) {
                        dev_dbg(&card->dev, "calling %pF\n", f->vendor_fixup);
                        f->vendor_fixup(card, f->data);
                }
index a99a33dd6f862cf6525c7870c6992c6d31a40f65..8cf313fd12c6ca8003f9af6887a6a087bd1f91b3 100644 (file)
@@ -478,7 +478,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
                card = oldcard;
                return 0;
        }
-       mmc_fixup_device(card);
+       mmc_fixup_device(card, NULL);
 
        if (card->type == MMC_TYPE_SD_COMBO) {
                err = mmc_sd_setup_card(host, card, oldcard != NULL);
index 30709f105b90c1bad022d1507f4ece7285b26afb..c1817f468c5e177720169507d81e18abdd2c0b0e 100644 (file)
@@ -11,6 +11,7 @@
 #define LINUX_MMC_CARD_H
 
 #include <linux/mmc/core.h>
+#include <linux/mod_devicetable.h>
 
 struct mmc_cid {
        unsigned int            manfid;
@@ -146,7 +147,93 @@ struct mmc_card {
        struct dentry           *debugfs_root;
 };
 
-void mmc_fixup_device(struct mmc_card *dev);
+/*
+ *  The world is not perfect and supplies us with broken mmc/sdio devices.
+ *  For at least a part of these bugs we need a work-around
+ */
+
+struct mmc_fixup {
+
+       /* CID-specific fields. */
+       const char *name;
+
+       /* Valid revision range */
+       u64 rev_start, rev_end;
+
+       unsigned int manfid;
+       unsigned short oemid;
+
+       /* SDIO-specfic fields. You can use SDIO_ANY_ID here of course */
+       u16 cis_vendor, cis_device;
+
+       void (*vendor_fixup)(struct mmc_card *card, int data);
+       int data;
+};
+
+#define CID_MANFID_ANY (-1ul)
+#define CID_OEMID_ANY ((unsigned short) -1)
+#define CID_NAME_ANY (NULL)
+
+#define END_FIXUP { 0 }
+
+#define _FIXUP_EXT(_name, _manfid, _oemid, _rev_start, _rev_end,       \
+                  _cis_vendor, _cis_device,                            \
+                  _fixup, _data)                                       \
+       {                                                  \
+               .name = (_name),                           \
+               .manfid = (_manfid),                       \
+               .oemid = (_oemid),                         \
+               .rev_start = (_rev_start),                 \
+               .rev_end = (_rev_end),                     \
+               .cis_vendor = (_cis_vendor),               \
+               .cis_device = (_cis_device),               \
+               .vendor_fixup = (_fixup),                  \
+               .data = (_data),                           \
+        }
+
+#define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end,    \
+                     _fixup, _data)                                    \
+       _FIXUP_EXT(_name, _manfid,                                      \
+                  _oemid, _rev_start, _rev_end,                        \
+                  SDIO_ANY_ID, SDIO_ANY_ID,                            \
+                  _fixup, _data)                                       \
+
+#define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \
+       MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data)
+
+#define SDIO_FIXUP(_vendor, _device, _fixup, _data)                    \
+       _FIXUP_EXT(CID_NAME_ANY, CID_MANFID_ANY,                        \
+                   CID_OEMID_ANY, 0, -1ull,                            \
+                  _vendor, _device,                                    \
+                  _fixup, _data)                                       \
+
+#define cid_rev(hwrev, fwrev, year, month)     \
+       (((u64) hwrev) << 40 |                  \
+        ((u64) fwrev) << 32 |                  \
+        ((u64) year) << 16 |                   \
+        ((u64) month))
+
+#define cid_rev_card(card)               \
+       cid_rev(card->cid.hwrev,          \
+                   card->cid.fwrev,      \
+                   card->cid.year,       \
+                   card->cid.month)
+
+/*
+ * This hook just adds a quirk unconditionnally
+ */
+static inline void __maybe_unused add_quirk(struct mmc_card *card, int data)
+{
+       card->quirks |= data;
+}
+
+/*
+ * This hook just removes a quirk unconditionnally
+ */
+static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
+{
+       card->quirks &= ~data;
+}
 
 #define mmc_card_mmc(c)                ((c)->type == MMC_TYPE_MMC)
 #define mmc_card_sd(c)         ((c)->type == MMC_TYPE_SD)
@@ -193,4 +280,7 @@ struct mmc_driver {
 extern int mmc_register_driver(struct mmc_driver *);
 extern void mmc_unregister_driver(struct mmc_driver *);
 
+extern void mmc_fixup_device(struct mmc_card *card,
+                            const struct mmc_fixup *table);
+
 #endif