board_usdhc.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (c) 2012, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "sdk.h"
  31. #include "registers/regsiomuxc.h"
  32. #include "registers/regsusdhc.h"
  33. ////////////////////////////////////////////////////////////////////////////////
  34. // Code
  35. ////////////////////////////////////////////////////////////////////////////////
  36. /*!
  37. * Set up the GPIO for USDHC
  38. */
  39. void usdhc_gpio_config(uint32_t instance)
  40. {
  41. switch (instance) {
  42. case HW_USDHC1:
  43. #if defined(BOARD_SABRE_AI)
  44. /* Select ALT5 mode of CSI0_DATA_EN for GPIO5_20 - SDb_WP(CSI0_DATA_EN_GPIO5_20) */
  45. gpio_set_gpio(GPIO_PORT5, 20);
  46. gpio_set_direction(GPIO_PORT5, 20, GPIO_GDIR_INPUT);
  47. #endif
  48. break;
  49. case HW_USDHC2:
  50. break;
  51. case HW_USDHC3:
  52. #if defined(BOARD_SABRE_AI)
  53. /* Select ALT5 mode of NANDF_CS2 for GPIO6_15 - SDa_CD_B(GPIO6_15) */
  54. gpio_set_gpio(GPIO_PORT6, 15);
  55. gpio_set_direction(GPIO_PORT6, 15, GPIO_GDIR_INPUT);
  56. /* Select ALT5 mode of SD2_DAT2 for GPIO1_13 - SDa_WP(SD2_DAT2_GPIO1_13) */
  57. gpio_set_gpio(GPIO_PORT1, 13);
  58. gpio_set_direction(GPIO_PORT1, 13, GPIO_GDIR_INPUT);
  59. #endif
  60. break;
  61. case HW_USDHC4:
  62. break;
  63. default:
  64. break;
  65. }
  66. }
  67. bool usdhc_card_detected(uint32_t instance)
  68. {
  69. bool ret_val = false;
  70. #if defined(BOARD_SABRE_AI)
  71. if (instance == HW_USDHC1) {
  72. // SDb_CD_B
  73. // Bit HIGH == pin LOW == Card Detected.
  74. if (BG_USDHC_PRES_STATE_CDPL(HW_USDHC_PRES_STATE_RD(instance))) {
  75. ret_val = true;
  76. }
  77. } else if (instance == HW_USDHC3) {
  78. // SDa_CD_B using GPIO6_15
  79. // Bit LOW == pin LOW == Card Detected.
  80. ret_val = gpio_get_level(GPIO_PORT6, 15) == GPIO_LOW_LEVEL;
  81. }
  82. #elif defined(BOARD_SMART_DEVICE)
  83. if (instance == HW_USDHC2) {
  84. // SD2_CD_B using GPIO2_02
  85. // Bit LOW == pin LOW == Card Detected.
  86. ret_val = gpio_get_level(GPIO_PORT2, 2) == GPIO_LOW_LEVEL;
  87. } else if (instance == HW_USDHC3) {
  88. // SD3_CD_B using GPIO2_00
  89. // Bit LOW == pin LOW == Card Detected.
  90. ret_val = gpio_get_level(GPIO_PORT2, 0) == GPIO_LOW_LEVEL;
  91. }
  92. #else
  93. if (BG_USDHC_PRES_STATE_CDPL(HW_USDHC_PRES_STATE_RD(instance))) {
  94. // Bit HIGH == pin LOW == Card Detected.
  95. ret_val = true;
  96. }
  97. #endif
  98. return ret_val;
  99. }
  100. bool usdhc_write_protected(uint32_t instance)
  101. {
  102. bool ret_val = true;
  103. #if defined(BOARD_SABRE_AI)
  104. if (instance == HW_USDHC1) {
  105. // SDb_WP (CSI0_DATA_EN_GPIO5_20)
  106. // Bit HIGH == pin HIGH == Write Protected.
  107. ret_val = gpio_get_level(GPIO_PORT5, 20) == GPIO_HIGH_LEVEL;
  108. } else if (instance == HW_USDHC3) {
  109. // SDa_WP (SD2_DAT2_GPIO1_13)
  110. // Bit HIGH == pin HIGH == Write Protected.
  111. ret_val = gpio_get_level(GPIO_PORT1, 13) == GPIO_HIGH_LEVEL;
  112. }
  113. #elif defined(BOARD_SMART_DEVICE)
  114. if (instance == HW_USDHC2) {
  115. // SD2_WP using GPIO2_03
  116. // Bit HIGH == pin HIGH == Write Protected.
  117. ret_val = gpio_get_level(GPIO_PORT2, 3) == GPIO_HIGH_LEVEL;
  118. } else if (instance == HW_USDHC3) {
  119. // SD3_WP using GPIO2_01
  120. // Bit HIGH == pin HIGH == Write Protected.
  121. ret_val = gpio_get_level(GPIO_PORT2, 1) == GPIO_HIGH_LEVEL;
  122. }
  123. #else
  124. if (BG_USDHC_PRES_STATE_WPSPL(HW_USDHC_PRES_STATE_RD(instance))) {
  125. // Bit HIGH == pin LOW == NOT Write Protected (Write Enabled).
  126. ret_val = false;
  127. }
  128. #endif
  129. return ret_val;
  130. }