blob: 06ee1aeaacec2693fd8f4a36b564902b1e738234 [file] [log] [blame]
Pierre Tardy57f0adc2011-02-06 19:03:46 +01001/*
Andrei Warkentin32780cd2011-04-11 17:02:15 -05002 * This file contains work-arounds for many known SD/MMC
3 * and SDIO hardware bugs.
Pierre Tardy57f0adc2011-02-06 19:03:46 +01004 *
Andrei Warkentin32780cd2011-04-11 17:02:15 -05005 * Copyright (c) 2011 Andrei Warkentin <andreiw@motorola.com>
Pierre Tardy57f0adc2011-02-06 19:03:46 +01006 * Copyright (c) 2011 Pierre Tardy <tardyp@gmail.com>
7 * Inspired from pci fixup code:
8 * Copyright (c) 1999 Martin Mares <mj@ucw.cz>
9 *
10 */
11
12#include <linux/types.h>
13#include <linux/kernel.h>
Paul Gortmaker3ef77af2011-07-10 12:42:00 -040014#include <linux/export.h>
Pierre Tardy57f0adc2011-02-06 19:03:46 +010015#include <linux/mmc/card.h>
Pierre Tardy57f0adc2011-02-06 19:03:46 +010016
Andrei Warkentin32780cd2011-04-11 17:02:15 -050017#ifndef SDIO_VENDOR_ID_TI
18#define SDIO_VENDOR_ID_TI 0x0097
19#endif
Pierre Tardy57f0adc2011-02-06 19:03:46 +010020
Andrei Warkentin32780cd2011-04-11 17:02:15 -050021#ifndef SDIO_DEVICE_ID_TI_WL1271
22#define SDIO_DEVICE_ID_TI_WL1271 0x4076
23#endif
Pierre Tardy57f0adc2011-02-06 19:03:46 +010024
Stefan Nilsson XK9a0da642011-09-15 17:43:04 +020025#ifndef SDIO_VENDOR_ID_STE
26#define SDIO_VENDOR_ID_STE 0x0020
27#endif
28
29#ifndef SDIO_DEVICE_ID_STE_CW1200
30#define SDIO_DEVICE_ID_STE_CW1200 0x2280
31#endif
32
Pierre Tardydb993502011-02-06 19:03:47 +010033/*
34 * This hook just adds a quirk for all sdio devices
35 */
36static void add_quirk_for_sdio_devices(struct mmc_card *card, int data)
37{
38 if (mmc_card_sdio(card))
39 card->quirks |= data;
40}
41
Pierre Tardy57f0adc2011-02-06 19:03:46 +010042static const struct mmc_fixup mmc_fixup_methods[] = {
Pierre Tardydb993502011-02-06 19:03:47 +010043 /* by default sdio devices are considered CLK_GATING broken */
44 /* good cards will be whitelisted as they are tested */
Andrei Warkentin32780cd2011-04-11 17:02:15 -050045 SDIO_FIXUP(SDIO_ANY_ID, SDIO_ANY_ID,
46 add_quirk_for_sdio_devices,
47 MMC_QUIRK_BROKEN_CLK_GATING),
48
49 SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
50 remove_quirk, MMC_QUIRK_BROKEN_CLK_GATING),
51
52 SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
53 add_quirk, MMC_QUIRK_NONSTD_FUNC_IF),
54
55 SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
56 add_quirk, MMC_QUIRK_DISABLE_CD),
57
Stefan Nilsson XK9a0da642011-09-15 17:43:04 +020058 SDIO_FIXUP(SDIO_VENDOR_ID_STE, SDIO_DEVICE_ID_STE_CW1200,
59 add_quirk, MMC_QUIRK_BROKEN_BYTE_MODE_512),
60
Andrei Warkentin32780cd2011-04-11 17:02:15 -050061 END_FIXUP
Pierre Tardy57f0adc2011-02-06 19:03:46 +010062};
63
Andrei Warkentin32780cd2011-04-11 17:02:15 -050064void mmc_fixup_device(struct mmc_card *card, const struct mmc_fixup *table)
Pierre Tardy57f0adc2011-02-06 19:03:46 +010065{
66 const struct mmc_fixup *f;
Andrei Warkentin32780cd2011-04-11 17:02:15 -050067 u64 rev = cid_rev_card(card);
Pierre Tardy57f0adc2011-02-06 19:03:46 +010068
Andrei Warkentin32780cd2011-04-11 17:02:15 -050069 /* Non-core specific workarounds. */
70 if (!table)
71 table = mmc_fixup_methods;
72
73 for (f = table; f->vendor_fixup; f++) {
74 if ((f->manfid == CID_MANFID_ANY ||
75 f->manfid == card->cid.manfid) &&
76 (f->oemid == CID_OEMID_ANY ||
77 f->oemid == card->cid.oemid) &&
78 (f->name == CID_NAME_ANY ||
79 !strncmp(f->name, card->cid.prod_name,
80 sizeof(card->cid.prod_name))) &&
81 (f->cis_vendor == card->cis.vendor ||
82 f->cis_vendor == (u16) SDIO_ANY_ID) &&
83 (f->cis_device == card->cis.device ||
84 f->cis_device == (u16) SDIO_ANY_ID) &&
85 rev >= f->rev_start && rev <= f->rev_end) {
Pierre Tardy57f0adc2011-02-06 19:03:46 +010086 dev_dbg(&card->dev, "calling %pF\n", f->vendor_fixup);
87 f->vendor_fixup(card, f->data);
88 }
89 }
90}
91EXPORT_SYMBOL(mmc_fixup_device);