sdhci-esdhc-imx.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Freescale eSDHC i.MX controller driver for the platform bus.
  3. *
  4. * derived from the OF-version.
  5. *
  6. * Copyright (c) 2010 Pengutronix e.K.
  7. * Author: Wolfram Sang <w.sang@pengutronix.de>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License.
  12. */
  13. #include <linux/io.h>
  14. #include <linux/delay.h>
  15. #include <linux/err.h>
  16. #include <linux/clk.h>
  17. #include <linux/mmc/host.h>
  18. #include <linux/mmc/sdhci-pltfm.h>
  19. #include <mach/hardware.h>
  20. #include "sdhci.h"
  21. #include "sdhci-pltfm.h"
  22. #include "sdhci-esdhc.h"
  23. static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg)
  24. {
  25. void __iomem *base = host->ioaddr + (reg & ~0x3);
  26. u32 shift = (reg & 0x3) * 8;
  27. writel(((readl(base) & ~(mask << shift)) | (val << shift)), base);
  28. }
  29. static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
  30. {
  31. if (unlikely(reg == SDHCI_HOST_VERSION))
  32. reg ^= 2;
  33. return readw(host->ioaddr + reg);
  34. }
  35. static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
  36. {
  37. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  38. switch (reg) {
  39. case SDHCI_TRANSFER_MODE:
  40. /*
  41. * Postpone this write, we must do it together with a
  42. * command write that is down below.
  43. */
  44. pltfm_host->scratchpad = val;
  45. return;
  46. case SDHCI_COMMAND:
  47. writel(val << 16 | pltfm_host->scratchpad,
  48. host->ioaddr + SDHCI_TRANSFER_MODE);
  49. return;
  50. case SDHCI_BLOCK_SIZE:
  51. val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
  52. break;
  53. }
  54. esdhc_clrset_le(host, 0xffff, val, reg);
  55. }
  56. static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
  57. {
  58. u32 new_val;
  59. switch (reg) {
  60. case SDHCI_POWER_CONTROL:
  61. /*
  62. * FSL put some DMA bits here
  63. * If your board has a regulator, code should be here
  64. */
  65. return;
  66. case SDHCI_HOST_CONTROL:
  67. /* FSL messed up here, so we can just keep those two */
  68. new_val = val & (SDHCI_CTRL_LED | SDHCI_CTRL_4BITBUS);
  69. /* ensure the endianess */
  70. new_val |= ESDHC_HOST_CONTROL_LE;
  71. /* DMA mode bits are shifted */
  72. new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5;
  73. esdhc_clrset_le(host, 0xffff, new_val, reg);
  74. return;
  75. }
  76. esdhc_clrset_le(host, 0xff, val, reg);
  77. }
  78. static unsigned int esdhc_pltfm_get_max_clock(struct sdhci_host *host)
  79. {
  80. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  81. return clk_get_rate(pltfm_host->clk);
  82. }
  83. static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host)
  84. {
  85. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  86. return clk_get_rate(pltfm_host->clk) / 256 / 16;
  87. }
  88. static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pdata)
  89. {
  90. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  91. struct clk *clk;
  92. clk = clk_get(mmc_dev(host->mmc), NULL);
  93. if (IS_ERR(clk)) {
  94. dev_err(mmc_dev(host->mmc), "clk err\n");
  95. return PTR_ERR(clk);
  96. }
  97. clk_enable(clk);
  98. pltfm_host->clk = clk;
  99. if (cpu_is_mx35() || cpu_is_mx51())
  100. host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
  101. /* Fix errata ENGcm07207 which is present on i.MX25 and i.MX35 */
  102. if (cpu_is_mx25() || cpu_is_mx35())
  103. host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK;
  104. return 0;
  105. }
  106. static void esdhc_pltfm_exit(struct sdhci_host *host)
  107. {
  108. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  109. clk_disable(pltfm_host->clk);
  110. clk_put(pltfm_host->clk);
  111. }
  112. static struct sdhci_ops sdhci_esdhc_ops = {
  113. .read_w = esdhc_readw_le,
  114. .write_w = esdhc_writew_le,
  115. .write_b = esdhc_writeb_le,
  116. .set_clock = esdhc_set_clock,
  117. .get_max_clock = esdhc_pltfm_get_max_clock,
  118. .get_min_clock = esdhc_pltfm_get_min_clock,
  119. };
  120. struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
  121. .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_ADMA,
  122. /* ADMA has issues. Might be fixable */
  123. .ops = &sdhci_esdhc_ops,
  124. .init = esdhc_pltfm_init,
  125. .exit = esdhc_pltfm_exit,
  126. };