pci_mmc.c 854 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (C) 2015, Google, Inc
  3. * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <errno.h>
  9. #include <malloc.h>
  10. #include <sdhci.h>
  11. #include <asm/pci.h>
  12. int pci_mmc_init(const char *name, struct pci_device_id *mmc_supported,
  13. int num_ids)
  14. {
  15. struct sdhci_host *mmc_host;
  16. pci_dev_t devbusfn;
  17. u32 iobase;
  18. int ret;
  19. int i;
  20. for (i = 0; i < num_ids; i++) {
  21. devbusfn = pci_find_devices(mmc_supported, i);
  22. if (devbusfn == -1)
  23. return -ENODEV;
  24. mmc_host = malloc(sizeof(struct sdhci_host));
  25. if (!mmc_host)
  26. return -ENOMEM;
  27. mmc_host->name = (char *)name;
  28. pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_0, &iobase);
  29. mmc_host->ioaddr = (void *)iobase;
  30. mmc_host->quirks = 0;
  31. ret = add_sdhci(mmc_host, 0, 0);
  32. if (ret)
  33. return ret;
  34. }
  35. return 0;
  36. }