pic32_sdhci.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 pic32_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 = pic32_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(dev), "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;
  40. host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
  41. "bus-width", 4);
  42. host->ops = &pic32_sdhci_ops;
  43. ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev),
  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. host->max_clk = f_min_max[1];
  50. ret = add_sdhci(host, 0, f_min_max[0]);
  51. if (ret)
  52. return ret;
  53. host->mmc->dev = dev;
  54. return 0;
  55. }
  56. static const struct udevice_id pic32_sdhci_ids[] = {
  57. { .compatible = "microchip,pic32mzda-sdhci" },
  58. { }
  59. };
  60. U_BOOT_DRIVER(pic32_sdhci_drv) = {
  61. .name = "pic32_sdhci",
  62. .id = UCLASS_MMC,
  63. .of_match = pic32_sdhci_ids,
  64. .probe = pic32_sdhci_probe,
  65. .priv_auto_alloc_size = sizeof(struct sdhci_host),
  66. };