mmc: add MMC_QUIRK_BROKEN_CLK_GATING
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / mmc / core / quirks.c
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
21 struct 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  */
30 static 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  */
38 static void __maybe_unused remove_quirk(struct mmc_card *card, int data)
39 {
40         card->quirks &= ~data;
41 }
42
43 /*
44  * This hook just adds a quirk for all sdio devices
45  */
46 static void add_quirk_for_sdio_devices(struct mmc_card *card, int data)
47 {
48         if (mmc_card_sdio(card))
49                 card->quirks |= data;
50 }
51
52 static const struct mmc_fixup mmc_fixup_methods[] = {
53         /* by default sdio devices are considered CLK_GATING broken */
54         /* good cards will be whitelisted as they are tested */
55         { SDIO_ANY_ID, SDIO_ANY_ID,
56                 add_quirk_for_sdio_devices, MMC_QUIRK_BROKEN_CLK_GATING }
57         { 0 }
58 };
59
60 void mmc_fixup_device(struct mmc_card *card)
61 {
62         const struct mmc_fixup *f;
63
64         for (f = mmc_fixup_methods; f->vendor_fixup; f++) {
65                 if ((f->vendor == card->cis.vendor
66                      || f->vendor == (u16) SDIO_ANY_ID) &&
67                     (f->device == card->cis.device
68                      || f->device == (u16) SDIO_ANY_ID)) {
69                         dev_dbg(&card->dev, "calling %pF\n", f->vendor_fixup);
70                         f->vendor_fixup(card, f->data);
71                 }
72         }
73 }
74 EXPORT_SYMBOL(mmc_fixup_device);