atmel_sdhci.c 869 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (C) 2015 Atmel Corporation
  3. * Wenyou.Yang <wenyou.yang@atmel.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <malloc.h>
  9. #include <sdhci.h>
  10. #include <asm/arch/clk.h>
  11. #define ATMEL_SDHC_MIN_FREQ 400000
  12. int atmel_sdhci_init(void *regbase, u32 id)
  13. {
  14. struct sdhci_host *host;
  15. u32 max_clk, min_clk = ATMEL_SDHC_MIN_FREQ;
  16. host = (struct sdhci_host *)calloc(1, sizeof(struct sdhci_host));
  17. if (!host) {
  18. printf("%s: sdhci_host calloc failed\n", __func__);
  19. return -ENOMEM;
  20. }
  21. host->name = "atmel_sdhci";
  22. host->ioaddr = regbase;
  23. host->quirks = 0;
  24. host->version = sdhci_readw(host, SDHCI_HOST_VERSION);
  25. max_clk = at91_get_periph_generated_clk(id);
  26. if (!max_clk) {
  27. printf("%s: Failed to get the proper clock\n", __func__);
  28. free(host);
  29. return -ENODEV;
  30. }
  31. add_sdhci(host, max_clk, min_clk);
  32. return 0;
  33. }