pic32_sdhci.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Support of SDHCI for Microchip PIC32 SoC.
  3. *
  4. * Copyright (C) 2015 Microchip Technology Inc.
  5. * Andrei Pistirica <andrei.pistirica@microchip.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <dm.h>
  10. #include <common.h>
  11. #include <sdhci.h>
  12. #include <linux/errno.h>
  13. #include <mach/pic32.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. static int pci32_sdhci_get_cd(struct sdhci_host *host)
  16. {
  17. /* PIC32 SDHCI CD errata:
  18. * - set CD_TEST and clear CD_TEST_INS bit
  19. */
  20. sdhci_writeb(host, SDHCI_CTRL_CD_TEST, SDHCI_HOST_CONTROL);
  21. return 0;
  22. }
  23. static const struct sdhci_ops pic32_sdhci_ops = {
  24. .get_cd = pci32_sdhci_get_cd,
  25. };
  26. static int pic32_sdhci_probe(struct udevice *dev)
  27. {
  28. struct sdhci_host *host = dev_get_priv(dev);
  29. const void *fdt = gd->fdt_blob;
  30. u32 f_min_max[2];
  31. fdt_addr_t addr;
  32. fdt_size_t size;
  33. int ret;
  34. addr = fdtdec_get_addr_size(fdt, dev->of_offset, "reg", &size);
  35. if (addr == FDT_ADDR_T_NONE)
  36. return -EINVAL;
  37. host->ioaddr = ioremap(addr, size);
  38. host->name = dev->name;
  39. host->quirks = SDHCI_QUIRK_NO_HISPD_BIT | SDHCI_QUIRK_NO_CD;
  40. host->bus_width = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
  41. "bus-width", 4);
  42. host->ops = &pic32_sdhci_ops;
  43. ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset,
  44. "clock-freq-min-max", f_min_max, 2);
  45. if (ret) {
  46. printf("sdhci: clock-freq-min-max not found\n");
  47. return ret;
  48. }
  49. ret = add_sdhci(host, f_min_max[1], f_min_max[0]);
  50. if (ret)
  51. return ret;
  52. host->mmc->dev = dev;
  53. return 0;
  54. }
  55. static const struct udevice_id pic32_sdhci_ids[] = {
  56. { .compatible = "microchip,pic32mzda-sdhci" },
  57. { }
  58. };
  59. U_BOOT_DRIVER(pic32_sdhci_drv) = {
  60. .name = "pic32_sdhci",
  61. .id = UCLASS_MMC,
  62. .of_match = pic32_sdhci_ids,
  63. .probe = pic32_sdhci_probe,
  64. .priv_auto_alloc_size = sizeof(struct sdhci_host),
  65. };