aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Tardy <pierre.tardy@intel.com>2011-02-06 13:03:46 -0500
committerChris Ball <cjb@laptop.org>2011-03-15 13:48:33 -0400
commit57f0adc7eaaf4315d568e72069dbe48aa7e20995 (patch)
tree233c66fd4f21b977f532702ce9427023b2e53e09
parent66c036e0142fed2484d58a2d3c7a4d21ba32b6a6 (diff)
mmc: add per device quirk placeholder
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. 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>
-rw-r--r--drivers/mmc/core/Makefile3
-rw-r--r--drivers/mmc/core/core.h2
-rw-r--r--drivers/mmc/core/quirks.c61
-rw-r--r--drivers/mmc/core/sdio.c1
-rw-r--r--include/linux/mmc/card.h2
5 files changed, 68 insertions, 1 deletions
diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile
index 86b479119332..639501970b41 100644
--- a/drivers/mmc/core/Makefile
+++ b/drivers/mmc/core/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_MMC) += mmc_core.o
6mmc_core-y := core.o bus.o host.o \ 6mmc_core-y := core.o bus.o host.o \
7 mmc.o mmc_ops.o sd.o sd_ops.o \ 7 mmc.o mmc_ops.o sd.o sd_ops.o \
8 sdio.o sdio_ops.o sdio_bus.o \ 8 sdio.o sdio_ops.o sdio_bus.o \
9 sdio_cis.o sdio_io.o sdio_irq.o 9 sdio_cis.o sdio_io.o sdio_irq.o \
10 quirks.o
10 11
11mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o 12mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index ca1fdde29df6..20b1c0831eac 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -61,6 +61,8 @@ int mmc_attach_mmc(struct mmc_host *host);
61int mmc_attach_sd(struct mmc_host *host); 61int mmc_attach_sd(struct mmc_host *host);
62int mmc_attach_sdio(struct mmc_host *host); 62int mmc_attach_sdio(struct mmc_host *host);
63 63
64void mmc_fixup_device(struct mmc_card *card);
65
64/* Module parameters */ 66/* Module parameters */
65extern int use_spi_crc; 67extern int use_spi_crc;
66 68
diff --git a/drivers/mmc/core/quirks.c b/drivers/mmc/core/quirks.c
new file mode 100644
index 000000000000..e18cb49c12b1
--- /dev/null
+++ b/drivers/mmc/core/quirks.c
@@ -0,0 +1,61 @@
1/*
2 * This file contains work-arounds for many known sdio hardware
3 * bugs.
4 *
5 * Copyright (c) 2011 Pierre Tardy <tardyp@gmail.com>
6 * Inspired from pci fixup code:
7 * Copyright (c) 1999 Martin Mares <mj@ucw.cz>
8 *
9 */
10
11#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/mmc/card.h>
14#include <linux/mod_devicetable.h>
15
16/*
17 * The world is not perfect and supplies us with broken mmc/sdio devices.
18 * For at least a part of these bugs we need a work-around
19 */
20
21struct mmc_fixup {
22 u16 vendor, device; /* You can use SDIO_ANY_ID here of course */
23 void (*vendor_fixup)(struct mmc_card *card, int data);
24 int data;
25};
26
27/*
28 * This hook just adds a quirk unconditionnally
29 */
30static void __maybe_unused add_quirk(struct mmc_card *card, int data)
31{
32 card->quirks |= data;
33}
34
35/*
36 * This hook just removes a quirk unconditionnally
37 */
38static void __maybe_unused remove_quirk(struct mmc_card *card, int data)
39{
40 card->quirks &= ~data;
41}
42
43static const struct mmc_fixup mmc_fixup_methods[] = {
44 { 0 }
45};
46
47void mmc_fixup_device(struct mmc_card *card)
48{
49 const struct mmc_fixup *f;
50
51 for (f = mmc_fixup_methods; f->vendor_fixup; f++) {
52 if ((f->vendor == card->cis.vendor
53 || f->vendor == (u16) SDIO_ANY_ID) &&
54 (f->device == card->cis.device
55 || f->device == (u16) SDIO_ANY_ID)) {
56 dev_dbg(&card->dev, "calling %pF\n", f->vendor_fixup);
57 f->vendor_fixup(card, f->data);
58 }
59 }
60}
61EXPORT_SYMBOL(mmc_fixup_device);
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index ebc62ad4cc56..c9fbb777440d 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -458,6 +458,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
458 458
459 card = oldcard; 459 card = oldcard;
460 } 460 }
461 mmc_fixup_device(card);
461 462
462 if (card->type == MMC_TYPE_SD_COMBO) { 463 if (card->type == MMC_TYPE_SD_COMBO) {
463 err = mmc_sd_setup_card(host, card, oldcard != NULL); 464 err = mmc_sd_setup_card(host, card, oldcard != NULL);
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 4652cf9c5442..ad7413854f79 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -151,6 +151,8 @@ struct mmc_card {
151 struct dentry *debugfs_root; 151 struct dentry *debugfs_root;
152}; 152};
153 153
154void mmc_fixup_device(struct mmc_card *dev);
155
154#define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC) 156#define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC)
155#define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD) 157#define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD)
156#define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO) 158#define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO)