socfpga_dw_mmc.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * (C) Copyright 2013 Altera Corporation <www.altera.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <malloc.h>
  8. #include <dwmmc.h>
  9. #include <errno.h>
  10. #include <asm/arch/dwmmc.h>
  11. #include <asm/arch/clock_manager.h>
  12. #include <asm/arch/system_manager.h>
  13. static const struct socfpga_clock_manager *clock_manager_base =
  14. (void *)SOCFPGA_CLKMGR_ADDRESS;
  15. static const struct socfpga_system_manager *system_manager_base =
  16. (void *)SOCFPGA_SYSMGR_ADDRESS;
  17. static void socfpga_dwmci_clksel(struct dwmci_host *host)
  18. {
  19. unsigned int drvsel;
  20. unsigned int smplsel;
  21. /* Disable SDMMC clock. */
  22. clrbits_le32(&clock_manager_base->per_pll.en,
  23. CLKMGR_PERPLLGRP_EN_SDMMCCLK_MASK);
  24. /* Configures drv_sel and smpl_sel */
  25. drvsel = CONFIG_SOCFPGA_DWMMC_DRVSEL;
  26. smplsel = CONFIG_SOCFPGA_DWMMC_SMPSEL;
  27. debug("%s: drvsel %d smplsel %d\n", __func__, drvsel, smplsel);
  28. writel(SYSMGR_SDMMC_CTRL_SET(smplsel, drvsel),
  29. &system_manager_base->sdmmcgrp_ctrl);
  30. debug("%s: SYSMGR_SDMMCGRP_CTRL_REG = 0x%x\n", __func__,
  31. readl(&system_manager_base->sdmmcgrp_ctrl));
  32. /* Enable SDMMC clock */
  33. setbits_le32(&clock_manager_base->per_pll.en,
  34. CLKMGR_PERPLLGRP_EN_SDMMCCLK_MASK);
  35. }
  36. int socfpga_dwmmc_init(u32 regbase, int bus_width, int index)
  37. {
  38. struct dwmci_host *host;
  39. unsigned long clk = cm_get_mmc_controller_clk_hz();
  40. if (clk == 0) {
  41. printf("%s: MMC clock is zero!", __func__);
  42. return -EINVAL;
  43. }
  44. /* calloc for zero init */
  45. host = calloc(1, sizeof(struct dwmci_host));
  46. if (!host) {
  47. printf("%s: calloc() failed!\n", __func__);
  48. return -ENOMEM;
  49. }
  50. host->name = "SOCFPGA DWMMC";
  51. host->ioaddr = (void *)regbase;
  52. host->buswidth = bus_width;
  53. host->clksel = socfpga_dwmci_clksel;
  54. host->dev_index = index;
  55. /* fixed clock divide by 4 which due to the SDMMC wrapper */
  56. host->bus_hz = clk;
  57. host->fifoth_val = MSIZE(0x2) |
  58. RX_WMARK(CONFIG_SOCFPGA_DWMMC_FIFO_DEPTH / 2 - 1) |
  59. TX_WMARK(CONFIG_SOCFPGA_DWMMC_FIFO_DEPTH / 2);
  60. return add_dwmci(host, host->bus_hz, 400000);
  61. }