sdhci-esdhc-imx.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "sdhci.h"
  20. #include "sdhci-pltfm.h"
  21. #include "sdhci-esdhc.h"
  22. static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg)
  23. {
  24. void __iomem *base = host->ioaddr + (reg & ~0x3);
  25. u32 shift = (reg & 0x3) * 8;
  26. writel(((readl(base) & ~(mask << shift)) | (val << shift)), base);
  27. }
  28. static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
  29. {
  30. if (unlikely(reg == SDHCI_HOST_VERSION))
  31. reg ^= 2;
  32. return readw(host->ioaddr + reg);
  33. }
  34. static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
  35. {
  36. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  37. switch (reg) {
  38. case SDHCI_TRANSFER_MODE:
  39. /*
  40. * Postpone this write, we must do it together with a
  41. * command write that is down below.
  42. */
  43. pltfm_host->scratchpad = val;
  44. return;
  45. case SDHCI_COMMAND:
  46. writel(val << 16 | pltfm_host->scratchpad,
  47. host->ioaddr + SDHCI_TRANSFER_MODE);
  48. return;
  49. case SDHCI_BLOCK_SIZE:
  50. val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
  51. break;
  52. }
  53. esdhc_clrset_le(host, 0xffff, val, reg);
  54. }
  55. static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
  56. {
  57. u32 new_val;
  58. switch (reg) {
  59. case SDHCI_POWER_CONTROL:
  60. /*
  61. * FSL put some DMA bits here
  62. * If your board has a regulator, code should be here
  63. */
  64. return;
  65. case SDHCI_HOST_CONTROL:
  66. /* FSL messed up here, so we can just keep those two */
  67. new_val = val & (SDHCI_CTRL_LED | SDHCI_CTRL_4BITBUS);
  68. /* ensure the endianess */
  69. new_val |= ESDHC_HOST_CONTROL_LE;
  70. /* DMA mode bits are shifted */
  71. new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5;
  72. esdhc_clrset_le(host, 0xffff, new_val, reg);
  73. return;
  74. }
  75. esdhc_clrset_le(host, 0xff, val, reg);
  76. }
  77. static unsigned int esdhc_pltfm_get_max_clock(struct sdhci_host *host)
  78. {
  79. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  80. return clk_get_rate(pltfm_host->clk);
  81. }
  82. static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host)
  83. {
  84. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  85. return clk_get_rate(pltfm_host->clk) / 256 / 16;
  86. }
  87. static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pdata)
  88. {
  89. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  90. struct clk *clk;
  91. clk = clk_get(mmc_dev(host->mmc), NULL);
  92. if (IS_ERR(clk)) {
  93. dev_err(mmc_dev(host->mmc), "clk err\n");
  94. return PTR_ERR(clk);
  95. }
  96. clk_enable(clk);
  97. pltfm_host->clk = clk;
  98. return 0;
  99. }
  100. static void esdhc_pltfm_exit(struct sdhci_host *host)
  101. {
  102. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  103. clk_disable(pltfm_host->clk);
  104. clk_put(pltfm_host->clk);
  105. }
  106. static struct sdhci_ops sdhci_esdhc_ops = {
  107. .read_w = esdhc_readw_le,
  108. .write_w = esdhc_writew_le,
  109. .write_b = esdhc_writeb_le,
  110. .set_clock = esdhc_set_clock,
  111. .get_max_clock = esdhc_pltfm_get_max_clock,
  112. .get_min_clock = esdhc_pltfm_get_min_clock,
  113. };
  114. struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
  115. .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_NO_MULTIBLOCK
  116. | SDHCI_QUIRK_BROKEN_ADMA,
  117. /* ADMA has issues. Might be fixable */
  118. /* NO_MULTIBLOCK might be MX35 only (Errata: ENGcm07207) */
  119. .ops = &sdhci_esdhc_ops,
  120. .init = esdhc_pltfm_init,
  121. .exit = esdhc_pltfm_exit,
  122. };