mmc: add per device quirk placeholder
authorPierre Tardy <pierre.tardy@intel.com>
Sun, 6 Feb 2011 18:03:46 +0000 (19:03 +0100)
committerKen Sumrall <ksumrall@android.com>
Thu, 7 Apr 2011 22:18:38 +0000 (15:18 -0700)
Some cards have quirks valid for every platforms using current
platform quirk hooks leads to a lot of code and debug duplication.

So we inspire a bit from what exists in PCI subsystem and do our own
per vendorid/deviceid quirk.  We still drop the complexity of the pci
quirk system (with special section tables, and so on).
That can be added later if needed.

Change-Id: Ib67a3e97486023267f5ea3e7c6ef8fc99b13a704
Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
Acked-by: Linus Walleij <linus.walleij@stericsson.com>
Acked-by: Ohad Ben-Cohen <ohad@wizery.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
drivers/mmc/core/Makefile
drivers/mmc/core/core.h
drivers/mmc/core/quirks.c [new file with mode: 0644]
drivers/mmc/core/sdio.c
include/linux/mmc/card.h

index 889e5f898f6f99485c6b031aee41f5a6ff86d0aa..f25f6a5d6dddd6a99c1542c8768066dc1c1da799 100644 (file)
@@ -10,6 +10,7 @@ obj-$(CONFIG_MMC)             += mmc_core.o
 mmc_core-y                     := core.o bus.o host.o \
                                   mmc.o mmc_ops.o sd.o sd_ops.o \
                                   sdio.o sdio_ops.o sdio_bus.o \
-                                  sdio_cis.o sdio_io.o sdio_irq.o
+                                  sdio_cis.o sdio_io.o sdio_irq.o \
+                                  quirks.o
 
 mmc_core-$(CONFIG_DEBUG_FS)    += debugfs.o
index 9d9eef50e5d1976fb5d9874a00f4cf2db77c540a..cb686b976a348bafeb69d47ab7f4cc1279d3fa49 100644 (file)
@@ -56,6 +56,8 @@ 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;
diff --git a/drivers/mmc/core/quirks.c b/drivers/mmc/core/quirks.c
new file mode 100644 (file)
index 0000000..aa811fc
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ *  This file contains work-arounds for many known sdio hardware
+ *  bugs.
+ *
+ *  Copyright (c) 2011 Pierre Tardy <tardyp@gmail.com>
+ *  Inspired from pci fixup code:
+ *  Copyright (c) 1999 Martin Mares <mj@ucw.cz>
+ *
+ */
+
+#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 }
+};
+
+void mmc_fixup_device(struct mmc_card *card)
+{
+       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)) {
+                       dev_dbg(&card->dev, "calling %pF\n", f->vendor_fixup);
+                       f->vendor_fixup(card, f->data);
+               }
+       }
+}
+EXPORT_SYMBOL(mmc_fixup_device);
+
index 155efb1ac797355a8cb32a31321f0cefb6526edc..50749f560df2081887c650768a0cbbcafa2a1224 100644 (file)
@@ -480,6 +480,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
                card = oldcard;
                return 0;
        }
+       mmc_fixup_device(card);
 
        if (card->type == MMC_TYPE_SD_COMBO) {
                err = mmc_sd_setup_card(host, card, oldcard != NULL);
index 6b7525099e56a943f014c9fbfcc0c6bc45b62579..30709f105b90c1bad022d1507f4ece7285b26afb 100644 (file)
@@ -146,6 +146,8 @@ struct mmc_card {
        struct dentry           *debugfs_root;
 };
 
+void mmc_fixup_device(struct mmc_card *dev);
+
 #define mmc_card_mmc(c)                ((c)->type == MMC_TYPE_MMC)
 #define mmc_card_sd(c)         ((c)->type == MMC_TYPE_SD)
 #define mmc_card_sdio(c)       ((c)->type == MMC_TYPE_SDIO)