sdhci-esdhc.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Freescale eSDHC controller driver generics for OF and pltfm.
  3. *
  4. * Copyright (c) 2007 Freescale Semiconductor, Inc.
  5. * Copyright (c) 2009 MontaVista Software, Inc.
  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. #ifndef _DRIVERS_MMC_SDHCI_ESDHC_H
  14. #define _DRIVERS_MMC_SDHCI_ESDHC_H
  15. /*
  16. * Ops and quirks for the Freescale eSDHC controller.
  17. */
  18. #define ESDHC_DEFAULT_QUIRKS (SDHCI_QUIRK_FORCE_BLK_SZ_2048 | \
  19. SDHCI_QUIRK_NO_BUSY_IRQ | \
  20. SDHCI_QUIRK_NONSTANDARD_CLOCK | \
  21. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK | \
  22. SDHCI_QUIRK_PIO_NEEDS_DELAY | \
  23. SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET)
  24. #define ESDHC_SYSTEM_CONTROL 0x2c
  25. #define ESDHC_CLOCK_MASK 0x0000fff0
  26. #define ESDHC_PREDIV_SHIFT 8
  27. #define ESDHC_DIVIDER_SHIFT 4
  28. #define ESDHC_CLOCK_PEREN 0x00000004
  29. #define ESDHC_CLOCK_HCKEN 0x00000002
  30. #define ESDHC_CLOCK_IPGEN 0x00000001
  31. /* pltfm-specific */
  32. #define ESDHC_HOST_CONTROL_LE 0x20
  33. /*
  34. * P2020 interpretation of the SDHCI_HOST_CONTROL register
  35. */
  36. #define ESDHC_CTRL_4BITBUS (0x1 << 1)
  37. #define ESDHC_CTRL_8BITBUS (0x2 << 1)
  38. #define ESDHC_CTRL_BUSWIDTH_MASK (0x3 << 1)
  39. /* OF-specific */
  40. #define ESDHC_DMA_SYSCTL 0x40c
  41. #define ESDHC_DMA_SNOOP 0x00000040
  42. #define ESDHC_HOST_CONTROL_RES 0x05
  43. static inline void esdhc_set_clock(struct sdhci_host *host, unsigned int clock,
  44. unsigned int host_clock)
  45. {
  46. int pre_div = 2;
  47. int div = 1;
  48. u32 temp;
  49. if (clock == 0)
  50. goto out;
  51. temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
  52. temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
  53. | ESDHC_CLOCK_MASK);
  54. sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  55. while (host_clock / pre_div / 16 > clock && pre_div < 256)
  56. pre_div *= 2;
  57. while (host_clock / pre_div / div > clock && div < 16)
  58. div++;
  59. dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
  60. clock, host_clock / pre_div / div);
  61. pre_div >>= 1;
  62. div--;
  63. temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
  64. temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
  65. | (div << ESDHC_DIVIDER_SHIFT)
  66. | (pre_div << ESDHC_PREDIV_SHIFT));
  67. sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  68. mdelay(1);
  69. out:
  70. host->clock = clock;
  71. }
  72. #endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */