pci_mmc.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015, Google, Inc
  4. * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <malloc.h>
  10. #include <mapmem.h>
  11. #include <sdhci.h>
  12. #include <asm/pci.h>
  13. struct pci_mmc_plat {
  14. struct mmc_config cfg;
  15. struct mmc mmc;
  16. };
  17. struct pci_mmc_priv {
  18. struct sdhci_host host;
  19. void *base;
  20. };
  21. static int pci_mmc_probe(struct udevice *dev)
  22. {
  23. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  24. struct pci_mmc_plat *plat = dev_get_platdata(dev);
  25. struct pci_mmc_priv *priv = dev_get_priv(dev);
  26. struct sdhci_host *host = &priv->host;
  27. int ret;
  28. host->ioaddr = (void *)dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0,
  29. PCI_REGION_MEM);
  30. host->name = dev->name;
  31. host->mmc = &plat->mmc;
  32. host->mmc->dev = dev;
  33. ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
  34. if (ret)
  35. return ret;
  36. host->mmc->priv = &priv->host;
  37. upriv->mmc = host->mmc;
  38. return sdhci_probe(dev);
  39. }
  40. static int pci_mmc_bind(struct udevice *dev)
  41. {
  42. struct pci_mmc_plat *plat = dev_get_platdata(dev);
  43. return sdhci_bind(dev, &plat->mmc, &plat->cfg);
  44. }
  45. U_BOOT_DRIVER(pci_mmc) = {
  46. .name = "pci_mmc",
  47. .id = UCLASS_MMC,
  48. .bind = pci_mmc_bind,
  49. .probe = pci_mmc_probe,
  50. .ops = &sdhci_ops,
  51. .priv_auto_alloc_size = sizeof(struct pci_mmc_priv),
  52. .platdata_auto_alloc_size = sizeof(struct pci_mmc_plat),
  53. };
  54. static struct pci_device_id mmc_supported[] = {
  55. { PCI_DEVICE_CLASS(PCI_CLASS_SYSTEM_SDHCI << 8, 0xffff00) },
  56. {},
  57. };
  58. U_BOOT_PCI_DEVICE(pci_mmc, mmc_supported);