s5p_sdhci.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * (C) Copyright 2012 SAMSUNG Electronics
  3. * Jaehoon Chung <jh80.chung@samsung.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <common.h>
  20. #include <malloc.h>
  21. #include <sdhci.h>
  22. #include <asm/arch/mmc.h>
  23. #include <asm/arch/clk.h>
  24. static char *S5P_NAME = "SAMSUNG SDHCI";
  25. static void s5p_sdhci_set_control_reg(struct sdhci_host *host)
  26. {
  27. unsigned long val, ctrl;
  28. /*
  29. * SELCLKPADDS[17:16]
  30. * 00 = 2mA
  31. * 01 = 4mA
  32. * 10 = 7mA
  33. * 11 = 9mA
  34. */
  35. sdhci_writel(host, SDHCI_CTRL4_DRIVE_MASK(0x3), SDHCI_CONTROL4);
  36. val = sdhci_readl(host, SDHCI_CONTROL2);
  37. val &= SDHCI_CTRL2_SELBASECLK_SHIFT;
  38. val |= SDHCI_CTRL2_ENSTAASYNCCLR |
  39. SDHCI_CTRL2_ENCMDCNFMSK |
  40. SDHCI_CTRL2_ENFBCLKRX |
  41. SDHCI_CTRL2_ENCLKOUTHOLD;
  42. sdhci_writel(host, val, SDHCI_CONTROL2);
  43. /*
  44. * FCSEL3[31] FCSEL2[23] FCSEL1[15] FCSEL0[7]
  45. * FCSel[1:0] : Rx Feedback Clock Delay Control
  46. * Inverter delay means10ns delay if SDCLK 50MHz setting
  47. * 01 = Delay1 (basic delay)
  48. * 11 = Delay2 (basic delay + 2ns)
  49. * 00 = Delay3 (inverter delay)
  50. * 10 = Delay4 (inverter delay + 2ns)
  51. */
  52. val = SDHCI_CTRL3_FCSEL0 | SDHCI_CTRL3_FCSEL1;
  53. sdhci_writel(host, val, SDHCI_CONTROL3);
  54. /*
  55. * SELBASECLK[5:4]
  56. * 00/01 = HCLK
  57. * 10 = EPLL
  58. * 11 = XTI or XEXTCLK
  59. */
  60. ctrl = sdhci_readl(host, SDHCI_CONTROL2);
  61. ctrl &= ~SDHCI_CTRL2_SELBASECLK_MASK(0x3);
  62. ctrl |= SDHCI_CTRL2_SELBASECLK_MASK(0x2);
  63. sdhci_writel(host, ctrl, SDHCI_CONTROL2);
  64. }
  65. int s5p_sdhci_init(u32 regbase, int index, int bus_width)
  66. {
  67. struct sdhci_host *host = NULL;
  68. host = (struct sdhci_host *)malloc(sizeof(struct sdhci_host));
  69. if (!host) {
  70. printf("sdhci__host malloc fail!\n");
  71. return 1;
  72. }
  73. host->name = S5P_NAME;
  74. host->ioaddr = (void *)regbase;
  75. host->quirks = SDHCI_QUIRK_NO_HISPD_BIT | SDHCI_QUIRK_BROKEN_VOLTAGE |
  76. SDHCI_QUIRK_BROKEN_R1B | SDHCI_QUIRK_32BIT_DMA_ADDR |
  77. SDHCI_QUIRK_WAIT_SEND_CMD;
  78. host->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
  79. host->version = sdhci_readw(host, SDHCI_HOST_VERSION);
  80. host->set_control_reg = &s5p_sdhci_set_control_reg;
  81. host->set_clock = set_mmc_clk;
  82. host->index = index;
  83. host->host_caps = MMC_MODE_HC;
  84. add_sdhci(host, 52000000, 400000);
  85. return 0;
  86. }