blob: 4407d910071278aca923572a4f37d07992bb31c7 [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
Sujit Reddy Thummad9b46112012-01-24 10:46:33 +053033#ifndef SDIO_VENDOR_ID_MSM
34#define SDIO_VENDOR_ID_MSM 0x0070
35#endif
36
37#ifndef SDIO_DEVICE_ID_MSM_WCN1314
38#define SDIO_DEVICE_ID_MSM_WCN1314 0x2881
39#endif
40
Krishna Kondae5c79d72012-05-14 16:19:31 -070041#ifndef SDIO_VENDOR_ID_MSM_QCA
42#define SDIO_VENDOR_ID_MSM_QCA 0x271
43#endif
44
45#ifndef SDIO_DEVICE_ID_MSM_QCA_AR6003_1
46#define SDIO_DEVICE_ID_MSM_QCA_AR6003_1 0x300
47#endif
48
49#ifndef SDIO_DEVICE_ID_MSM_QCA_AR6003_2
50#define SDIO_DEVICE_ID_MSM_QCA_AR6003_2 0x301
51#endif
52
Pierre Tardydb993502011-02-06 19:03:47 +010053/*
54 * This hook just adds a quirk for all sdio devices
55 */
56static void add_quirk_for_sdio_devices(struct mmc_card *card, int data)
57{
58 if (mmc_card_sdio(card))
59 card->quirks |= data;
60}
61
Pierre Tardy57f0adc2011-02-06 19:03:46 +010062static const struct mmc_fixup mmc_fixup_methods[] = {
Pierre Tardydb993502011-02-06 19:03:47 +010063 /* by default sdio devices are considered CLK_GATING broken */
64 /* good cards will be whitelisted as they are tested */
Andrei Warkentin32780cd2011-04-11 17:02:15 -050065 SDIO_FIXUP(SDIO_ANY_ID, SDIO_ANY_ID,
66 add_quirk_for_sdio_devices,
67 MMC_QUIRK_BROKEN_CLK_GATING),
68
69 SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
70 remove_quirk, MMC_QUIRK_BROKEN_CLK_GATING),
71
Sujit Reddy Thummad9b46112012-01-24 10:46:33 +053072 SDIO_FIXUP(SDIO_VENDOR_ID_MSM, SDIO_DEVICE_ID_MSM_WCN1314,
73 remove_quirk, MMC_QUIRK_BROKEN_CLK_GATING),
74
Krishna Kondae5c79d72012-05-14 16:19:31 -070075 SDIO_FIXUP(SDIO_VENDOR_ID_MSM_QCA, SDIO_DEVICE_ID_MSM_QCA_AR6003_1,
76 remove_quirk, MMC_QUIRK_BROKEN_CLK_GATING),
77
78 SDIO_FIXUP(SDIO_VENDOR_ID_MSM_QCA, SDIO_DEVICE_ID_MSM_QCA_AR6003_2,
79 remove_quirk, MMC_QUIRK_BROKEN_CLK_GATING),
80
Andrei Warkentin32780cd2011-04-11 17:02:15 -050081 SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
82 add_quirk, MMC_QUIRK_NONSTD_FUNC_IF),
83
84 SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
85 add_quirk, MMC_QUIRK_DISABLE_CD),
86
Stefan Nilsson XK9a0da642011-09-15 17:43:04 +020087 SDIO_FIXUP(SDIO_VENDOR_ID_STE, SDIO_DEVICE_ID_STE_CW1200,
88 add_quirk, MMC_QUIRK_BROKEN_BYTE_MODE_512),
89
Andrei Warkentin32780cd2011-04-11 17:02:15 -050090 END_FIXUP
Pierre Tardy57f0adc2011-02-06 19:03:46 +010091};
92
Andrei Warkentin32780cd2011-04-11 17:02:15 -050093void mmc_fixup_device(struct mmc_card *card, const struct mmc_fixup *table)
Pierre Tardy57f0adc2011-02-06 19:03:46 +010094{
95 const struct mmc_fixup *f;
Andrei Warkentin32780cd2011-04-11 17:02:15 -050096 u64 rev = cid_rev_card(card);
Pierre Tardy57f0adc2011-02-06 19:03:46 +010097
Andrei Warkentin32780cd2011-04-11 17:02:15 -050098 /* Non-core specific workarounds. */
99 if (!table)
100 table = mmc_fixup_methods;
101
102 for (f = table; f->vendor_fixup; f++) {
103 if ((f->manfid == CID_MANFID_ANY ||
104 f->manfid == card->cid.manfid) &&
105 (f->oemid == CID_OEMID_ANY ||
106 f->oemid == card->cid.oemid) &&
107 (f->name == CID_NAME_ANY ||
108 !strncmp(f->name, card->cid.prod_name,
109 sizeof(card->cid.prod_name))) &&
Pratibhasagar V84af3732013-08-22 13:23:55 +0530110 (f->ext_csd_rev == EXT_CSD_REV_ANY ||
111 f->ext_csd_rev == card->ext_csd.rev) &&
Andrei Warkentin32780cd2011-04-11 17:02:15 -0500112 (f->cis_vendor == card->cis.vendor ||
113 f->cis_vendor == (u16) SDIO_ANY_ID) &&
114 (f->cis_device == card->cis.device ||
115 f->cis_device == (u16) SDIO_ANY_ID) &&
116 rev >= f->rev_start && rev <= f->rev_end) {
Pierre Tardy57f0adc2011-02-06 19:03:46 +0100117 dev_dbg(&card->dev, "calling %pF\n", f->vendor_fixup);
118 f->vendor_fixup(card, f->data);
119 }
120 }
121}
122EXPORT_SYMBOL(mmc_fixup_device);