sdhci-of-esdhc.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #include "sdhci-esdhc.h"
  21. static u16 esdhc_readw(struct sdhci_host *host, int reg)
  22. {
  23. u16 ret;
  24. if (unlikely(reg == SDHCI_HOST_VERSION))
  25. ret = in_be16(host->ioaddr + reg);
  26. else
  27. ret = sdhci_be32bs_readw(host, reg);
  28. return ret;
  29. }
  30. static void esdhc_writew(struct sdhci_host *host, u16 val, int reg)
  31. {
  32. if (reg == SDHCI_BLOCK_SIZE) {
  33. /*
  34. * Two last DMA bits are reserved, and first one is used for
  35. * non-standard blksz of 4096 bytes that we don't support
  36. * yet. So clear the DMA boundary bits.
  37. */
  38. val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
  39. }
  40. sdhci_be32bs_writew(host, val, reg);
  41. }
  42. static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
  43. {
  44. /* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */
  45. if (reg == SDHCI_HOST_CONTROL)
  46. val &= ~ESDHC_HOST_CONTROL_RES;
  47. sdhci_be32bs_writeb(host, val, reg);
  48. }
  49. static int esdhc_of_enable_dma(struct sdhci_host *host)
  50. {
  51. setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP);
  52. return 0;
  53. }
  54. static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host)
  55. {
  56. struct sdhci_of_host *of_host = sdhci_priv(host);
  57. return of_host->clock;
  58. }
  59. static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
  60. {
  61. struct sdhci_of_host *of_host = sdhci_priv(host);
  62. return of_host->clock / 256 / 16;
  63. }
  64. struct sdhci_of_data sdhci_esdhc = {
  65. /* card detection could be handled via GPIO */
  66. .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION
  67. | SDHCI_QUIRK_NO_CARD_NO_RESET,
  68. .ops = {
  69. .read_l = sdhci_be32bs_readl,
  70. .read_w = esdhc_readw,
  71. .read_b = sdhci_be32bs_readb,
  72. .write_l = sdhci_be32bs_writel,
  73. .write_w = esdhc_writew,
  74. .write_b = esdhc_writeb,
  75. .set_clock = esdhc_set_clock,
  76. .enable_dma = esdhc_of_enable_dma,
  77. .get_max_clock = esdhc_of_get_max_clock,
  78. .get_min_clock = esdhc_of_get_min_clock,
  79. },
  80. };