sdhci-of-esdhc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Freescale eSDHC controller driver.
  3. *
  4. * Copyright (c) 2007 Freescale Semiconductor, Inc.
  5. * Copyright (c) 2009 MontaVista Software, Inc.
  6. *
  7. * Authors: Xiaobo Xie <X.Xie@freescale.com>
  8. * Anton Vorontsov <avorontsov@ru.mvista.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or (at
  13. * your option) any later version.
  14. */
  15. #include <linux/io.h>
  16. #include <linux/delay.h>
  17. #include <linux/mmc/host.h>
  18. #include "sdhci-of.h"
  19. #include "sdhci.h"
  20. /*
  21. * Ops and quirks for the Freescale eSDHC controller.
  22. */
  23. #define ESDHC_DMA_SYSCTL 0x40c
  24. #define ESDHC_DMA_SNOOP 0x00000040
  25. #define ESDHC_SYSTEM_CONTROL 0x2c
  26. #define ESDHC_CLOCK_MASK 0x0000fff0
  27. #define ESDHC_PREDIV_SHIFT 8
  28. #define ESDHC_DIVIDER_SHIFT 4
  29. #define ESDHC_CLOCK_PEREN 0x00000004
  30. #define ESDHC_CLOCK_HCKEN 0x00000002
  31. #define ESDHC_CLOCK_IPGEN 0x00000001
  32. #define ESDHC_HOST_CONTROL_RES 0x05
  33. static u16 esdhc_readw(struct sdhci_host *host, int reg)
  34. {
  35. u16 ret;
  36. if (unlikely(reg == SDHCI_HOST_VERSION))
  37. ret = in_be16(host->ioaddr + reg);
  38. else
  39. ret = sdhci_be32bs_readw(host, reg);
  40. return ret;
  41. }
  42. static void esdhc_writew(struct sdhci_host *host, u16 val, int reg)
  43. {
  44. if (reg == SDHCI_BLOCK_SIZE) {
  45. /*
  46. * Two last DMA bits are reserved, and first one is used for
  47. * non-standard blksz of 4096 bytes that we don't support
  48. * yet. So clear the DMA boundary bits.
  49. */
  50. val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
  51. }
  52. sdhci_be32bs_writew(host, val, reg);
  53. }
  54. static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
  55. {
  56. /* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */
  57. if (reg == SDHCI_HOST_CONTROL)
  58. val &= ~ESDHC_HOST_CONTROL_RES;
  59. sdhci_be32bs_writeb(host, val, reg);
  60. }
  61. static void esdhc_set_clock(struct sdhci_host *host, unsigned int clock)
  62. {
  63. int pre_div = 2;
  64. int div = 1;
  65. clrbits32(host->ioaddr + ESDHC_SYSTEM_CONTROL, ESDHC_CLOCK_IPGEN |
  66. ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
  67. if (clock == 0)
  68. goto out;
  69. while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
  70. pre_div *= 2;
  71. while (host->max_clk / pre_div / div > clock && div < 16)
  72. div++;
  73. dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
  74. clock, host->max_clk / pre_div / div);
  75. pre_div >>= 1;
  76. div--;
  77. setbits32(host->ioaddr + ESDHC_SYSTEM_CONTROL, ESDHC_CLOCK_IPGEN |
  78. ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN |
  79. div << ESDHC_DIVIDER_SHIFT | pre_div << ESDHC_PREDIV_SHIFT);
  80. mdelay(100);
  81. out:
  82. host->clock = clock;
  83. }
  84. static int esdhc_enable_dma(struct sdhci_host *host)
  85. {
  86. setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP);
  87. return 0;
  88. }
  89. static unsigned int esdhc_get_max_clock(struct sdhci_host *host)
  90. {
  91. struct sdhci_of_host *of_host = sdhci_priv(host);
  92. return of_host->clock;
  93. }
  94. static unsigned int esdhc_get_min_clock(struct sdhci_host *host)
  95. {
  96. struct sdhci_of_host *of_host = sdhci_priv(host);
  97. return of_host->clock / 256 / 16;
  98. }
  99. struct sdhci_of_data sdhci_esdhc = {
  100. .quirks = SDHCI_QUIRK_FORCE_BLK_SZ_2048 |
  101. SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  102. SDHCI_QUIRK_NO_BUSY_IRQ |
  103. SDHCI_QUIRK_NONSTANDARD_CLOCK |
  104. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  105. SDHCI_QUIRK_PIO_NEEDS_DELAY |
  106. SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET |
  107. SDHCI_QUIRK_NO_CARD_NO_RESET,
  108. .ops = {
  109. .readl = sdhci_be32bs_readl,
  110. .readw = esdhc_readw,
  111. .readb = sdhci_be32bs_readb,
  112. .writel = sdhci_be32bs_writel,
  113. .writew = esdhc_writew,
  114. .writeb = esdhc_writeb,
  115. .set_clock = esdhc_set_clock,
  116. .enable_dma = esdhc_enable_dma,
  117. .get_max_clock = esdhc_get_max_clock,
  118. .get_min_clock = esdhc_get_min_clock,
  119. },
  120. };