pic32_sdhci.c 1.8 KB

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