socfpga_dw_mmc.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <asm/arch/dwmmc.h>
  10. #include <asm/arch/clock_manager.h>
  11. #include <asm/arch/system_manager.h>
  12. static const struct socfpga_clock_manager *clock_manager_base =
  13. (void *)SOCFPGA_CLKMGR_ADDRESS;
  14. static const struct socfpga_system_manager *system_manager_base =
  15. (void *)SOCFPGA_SYSMGR_ADDRESS;
  16. static char *SOCFPGA_NAME = "SOCFPGA DWMMC";
  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 = NULL;
  39. host = calloc(sizeof(struct dwmci_host), 1);
  40. if (!host) {
  41. printf("dwmci_host calloc fail!\n");
  42. return -1;
  43. }
  44. host->name = SOCFPGA_NAME;
  45. host->ioaddr = (void *)regbase;
  46. host->buswidth = bus_width;
  47. host->clksel = socfpga_dwmci_clksel;
  48. host->dev_index = index;
  49. /* fixed clock divide by 4 which due to the SDMMC wrapper */
  50. host->bus_hz = CONFIG_SOCFPGA_DWMMC_BUS_HZ;
  51. host->fifoth_val = MSIZE(0x2) |
  52. RX_WMARK(CONFIG_SOCFPGA_DWMMC_FIFO_DEPTH / 2 - 1) |
  53. TX_WMARK(CONFIG_SOCFPGA_DWMMC_FIFO_DEPTH / 2);
  54. return add_dwmci(host, host->bus_hz, 400000);
  55. }