quirks.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2017 ALLWINNERTECH TECHNOLOGY CO., LTD. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the
  12. * distribution.
  13. * 3. Neither the name of ALLWINNERTECH TECHNOLOGY CO., LTD. nor the names of
  14. * its contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "string.h" /* for strncmp() */
  30. #include "card.h"
  31. #include "_core.h"
  32. #ifdef CONFIG_USE_MMC_QUIRK
  33. #ifndef SDIO_VENDOR_ID_TI
  34. #define SDIO_VENDOR_ID_TI 0x0097
  35. #endif
  36. #ifndef SDIO_DEVICE_ID_TI_WL1271
  37. #define SDIO_DEVICE_ID_TI_WL1271 0x4076
  38. #endif
  39. #ifndef SDIO_VENDOR_ID_XR
  40. #define SDIO_VENDOR_ID_XR 0x0020
  41. #endif
  42. #ifndef SDIO_DEVICE_ID_XRADIO
  43. #define SDIO_DEVICE_ID_XRADIO 0x2281
  44. #endif
  45. static const struct mmc_fixup mmc_fixup_methods[] = {
  46. /* by default sdio devices are considered CLK_GATING broken */
  47. /* good cards will be whitelisted as they are tested */
  48. SDIO_FIXUP(SDIO_ANY_ID, SDIO_ANY_ID, add_quirk_for_sdio_devices,
  49. MMC_QUIRK_BROKEN_CLK_GATING),
  50. SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
  51. remove_quirk, MMC_QUIRK_BROKEN_CLK_GATING),
  52. SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
  53. add_quirk, MMC_QUIRK_NONSTD_FUNC_IF),
  54. SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
  55. add_quirk, MMC_QUIRK_DISABLE_CD),
  56. SDIO_FIXUP(SDIO_VENDOR_ID_XR, SDIO_DEVICE_ID_XRADIO,
  57. add_quirk, MMC_QUIRK_BROKEN_BYTE_MODE_512),
  58. END_FIXUP
  59. };
  60. void mmc_fixup_device(struct mmc_card *card, const struct mmc_fixup *table)
  61. {
  62. const struct mmc_fixup *f;
  63. uint64_t rev = cid_rev_card(card);
  64. /* Non-core specific workarounds. */
  65. if (!table)
  66. table = mmc_fixup_methods;
  67. for (f = table; f->vendor_fixup; f++) {
  68. if ((f->manfid == CID_MANFID_ANY ||
  69. f->manfid == card->cid.manfid) &&
  70. (f->oemid == CID_OEMID_ANY ||
  71. f->oemid == card->cid.oemid) &&
  72. (f->name == CID_NAME_ANY ||
  73. !strncmp(f->name, card->cid.prod_name,
  74. sizeof(card->cid.prod_name))) &&
  75. (f->cis_vendor == card->cis.vendor ||
  76. f->cis_vendor == (uint16_t) SDIO_ANY_ID) &&
  77. (f->cis_device == card->cis.device ||
  78. f->cis_device == (uint16_t) SDIO_ANY_ID) &&
  79. rev >= f->rev_start && rev <= f->rev_end) {
  80. SD_LOGD("%s calling %pF\n", __func__, f->vendor_fixup);
  81. f->vendor_fixup(card, f->data);
  82. }
  83. }
  84. }
  85. #endif