bcmstb_sdhci.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2018 Cisco Systems, Inc.
  4. *
  5. * Author: Thomas Fitzsimmons <fitzsim@fitzsim.org>
  6. */
  7. #include <common.h>
  8. #include <mach/sdhci.h>
  9. #include <malloc.h>
  10. #include <sdhci.h>
  11. /*
  12. * The BCMSTB SDHCI has a quirk in that its actual maximum frequency
  13. * capability is 100 MHz. The divisor that is eventually written to
  14. * SDHCI_CLOCK_CONTROL is calculated based on what the MMC device
  15. * reports, and relative to this maximum frequency.
  16. *
  17. * This define used to be set to 52000000 (52 MHz), the desired
  18. * maximum frequency, but that would result in the communication
  19. * actually running at 100 MHz (seemingly without issue), which is
  20. * out-of-spec.
  21. *
  22. * Now, by setting this to 0 (auto-detect), 100 MHz will be read from
  23. * the capabilities register, and the resulting divisor will be
  24. * doubled, meaning that the clock control register will be set to the
  25. * in-spec 52 MHz value.
  26. */
  27. #define BCMSTB_SDHCI_MAXIMUM_CLOCK_FREQUENCY 0
  28. /*
  29. * When the minimum clock frequency is set to 0 (auto-detect), U-Boot
  30. * sets it to 100 MHz divided by SDHCI_MAX_DIV_SPEC_300, or 48,875 Hz,
  31. * which results in the controller timing out when trying to
  32. * communicate with the MMC device. Hard-code this value to 400000
  33. * (400 kHz) to prevent this.
  34. */
  35. #define BCMSTB_SDHCI_MINIMUM_CLOCK_FREQUENCY 400000
  36. static char *BCMSTB_SDHCI_NAME = "bcmstb-sdhci";
  37. /*
  38. * This driver has only been tested with eMMC devices; SD devices may
  39. * not work.
  40. */
  41. int bcmstb_sdhci_init(phys_addr_t regbase)
  42. {
  43. struct sdhci_host *host = NULL;
  44. host = (struct sdhci_host *)malloc(sizeof(struct sdhci_host));
  45. if (!host) {
  46. printf("%s: Failed to allocate memory\n", __func__);
  47. return 1;
  48. }
  49. memset(host, 0, sizeof(*host));
  50. host->name = BCMSTB_SDHCI_NAME;
  51. host->ioaddr = (void *)regbase;
  52. host->quirks = 0;
  53. host->cfg.part_type = PART_TYPE_DOS;
  54. host->version = sdhci_readw(host, SDHCI_HOST_VERSION);
  55. return add_sdhci(host,
  56. BCMSTB_SDHCI_MAXIMUM_CLOCK_FREQUENCY,
  57. BCMSTB_SDHCI_MINIMUM_CLOCK_FREQUENCY);
  58. }