sdhci-esdhc.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. /* OF-specific */
  34. #define ESDHC_DMA_SYSCTL 0x40c
  35. #define ESDHC_DMA_SNOOP 0x00000040
  36. #define ESDHC_HOST_CONTROL_RES 0x05
  37. static inline void esdhc_set_clock(struct sdhci_host *host, unsigned int clock)
  38. {
  39. int pre_div = 2;
  40. int div = 1;
  41. u32 temp;
  42. temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
  43. temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
  44. | ESDHC_CLOCK_MASK);
  45. sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  46. if (clock == 0)
  47. goto out;
  48. while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
  49. pre_div *= 2;
  50. while (host->max_clk / pre_div / div > clock && div < 16)
  51. div++;
  52. dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
  53. clock, host->max_clk / pre_div / div);
  54. pre_div >>= 1;
  55. div--;
  56. temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
  57. temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
  58. | (div << ESDHC_DIVIDER_SHIFT)
  59. | (pre_div << ESDHC_PREDIV_SHIFT));
  60. sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  61. mdelay(100);
  62. out:
  63. host->clock = clock;
  64. }
  65. #endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */