Insei

Untitled

Aug 30th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.05 KB | None | 0 0
  1. static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
  2. {
  3. struct sdhci_host *host;
  4. int present;
  5. unsigned long flags;
  6. u32 tuning_opcode;
  7.  
  8. host = mmc_priv(mmc);
  9.  
  10. #ifdef CONFIG_DEBUG_FS
  11. if (mrq->data && mrq->data->blocks)
  12. update_stat(host, mrq->data->blksz, mrq->data->blocks,
  13. true, false, mrq->data->flags);
  14. #endif
  15. #ifndef CONFIG_MMC_CQ
  16. sdhci_runtime_pm_get(host);
  17. #endif
  18. present = mmc_gpio_get_cd(host->mmc);
  19.  
  20. spin_lock_irqsave(&host->lock, flags);
  21.  
  22. WARN_ON(host->mrq_cmd != NULL);
  23.  
  24. #ifndef SDHCI_USE_LEDS_CLASS
  25. sdhci_activate_led(host);
  26. #endif
  27.  
  28. /*
  29. * Ensure we don't send the STOP for non-SET_BLOCK_COUNTED
  30. * requests if Auto-CMD12 is enabled.
  31. */
  32. if (!MMC_CHECK_CMDQ_MODE(host) && !mrq->sbc && (host->flags & SDHCI_AUTO_CMD12)) {
  33. if (mrq->stop) {
  34. mrq->data->stop = NULL;
  35. mrq->stop = NULL;
  36. }
  37. }
  38.  
  39. host->mrq_cmd = mrq;
  40. host->mrq_cmd->data_early = 0;
  41.  
  42. /*
  43. * Firstly check card presence from cd-gpio. The return could
  44. * be one of the following possibilities:
  45. * negative: cd-gpio is not available
  46. * zero: cd-gpio is used, and card is removed
  47. * one: cd-gpio is used, and card is present
  48. */
  49. if (present < 0) {
  50. /* If polling, assume that the card is always present. */
  51. if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
  52. if (host->ops->get_cd)
  53. present = host->ops->get_cd(host);
  54. else
  55. present = 1;
  56. else
  57. present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
  58. SDHCI_CARD_PRESENT;
  59. }
  60.  
  61. if (!present || host->flags & SDHCI_DEVICE_DEAD) {
  62. host->mrq_cmd->cmd->error = -ENOMEDIUM;
  63. if (MMC_CHECK_CMDQ_MODE(host))
  64. tasklet_schedule(&host->finish_cmd_tasklet);
  65. else
  66. tasklet_schedule(&host->finish_tasklet);
  67. } else {
  68. u32 present_state;
  69.  
  70. present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
  71. /*
  72. * Check if the re-tuning timer has already expired and there
  73. * is no on-going data transfer. If so, we need to execute
  74. * tuning procedure before sending command.
  75. */
  76. if ((host->flags & SDHCI_NEEDS_RETUNING) &&
  77. !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ))) {
  78. if (!mmc->need_tuning || !mmc->ready_tuning) {
  79. if (!mmc->need_tuning)
  80. mmc->need_tuning = 1;
  81. goto end_tuning;
  82. }
  83.  
  84. if (mmc->card) {
  85. /* eMMC uses cmd21 but sd and sdio use cmd19 */
  86. tuning_opcode =
  87. mmc->card->type == MMC_TYPE_MMC ?
  88. MMC_SEND_TUNING_BLOCK_HS200 :
  89. MMC_SEND_TUNING_BLOCK;
  90. host->mrq_cmd = NULL;
  91. spin_unlock_irqrestore(&host->lock, flags);
  92. sdhci_execute_tuning(mmc, tuning_opcode);
  93. mmc->need_tuning = 0;
  94. mmc->ready_tuning = 0;
  95. spin_lock_irqsave(&host->lock, flags);
  96.  
  97. end_tuning:
  98. /* Restore original mmc_request structure */
  99. host->mrq_cmd = mrq;
  100. }
  101. }
  102.  
  103. /* For a data cmd, check for plat specific preparation */
  104. spin_unlock_irqrestore(&host->lock, flags);
  105. if (mrq->data)
  106. host->ops->platform_get_bus(host);
  107. spin_lock_irqsave(&host->lock, flags);
  108.  
  109. if (!MMC_CHECK_CMDQ_MODE(host) &&
  110. (mrq->sbc && !(host->flags & SDHCI_AUTO_CMD23)))
  111. sdhci_send_command(host, mrq->sbc);
  112. else if (MMC_CHECK_CMDQ_MODE(host) && mrq->sbc)
  113. sdhci_send_command(host, mrq->sbc);
  114. else {
  115. sdhci_send_command(host, mrq->cmd);
  116. }
  117. }
  118.  
  119. mmiowb();
  120. spin_unlock_irqrestore(&host->lock, flags);
  121. }
Advertisement
Add Comment
Please, Sign In to add comment