pci_mmc.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <dm.h>
  9. #include <errno.h>
  10. #include <malloc.h>
  11. #include <mapmem.h>
  12. #include <sdhci.h>
  13. #include <asm/pci.h>
  14. struct pci_mmc_plat {
  15. struct mmc_config cfg;
  16. struct mmc mmc;
  17. };
  18. struct pci_mmc_priv {
  19. struct sdhci_host host;
  20. void *base;
  21. };
  22. static int pci_mmc_probe(struct udevice *dev)
  23. {
  24. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  25. struct pci_mmc_plat *plat = dev_get_platdata(dev);
  26. struct pci_mmc_priv *priv = dev_get_priv(dev);
  27. struct sdhci_host *host = &priv->host;
  28. u32 ioaddr;
  29. int ret;
  30. dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &ioaddr);
  31. host->ioaddr = map_sysmem(ioaddr, 0);
  32. host->name = dev->name;
  33. ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
  34. if (ret)
  35. return ret;
  36. host->mmc = &plat->mmc;
  37. host->mmc->priv = &priv->host;
  38. host->mmc->dev = dev;
  39. upriv->mmc = host->mmc;
  40. return sdhci_probe(dev);
  41. }
  42. static int pci_mmc_bind(struct udevice *dev)
  43. {
  44. struct pci_mmc_plat *plat = dev_get_platdata(dev);
  45. return sdhci_bind(dev, &plat->mmc, &plat->cfg);
  46. }
  47. U_BOOT_DRIVER(pci_mmc) = {
  48. .name = "pci_mmc",
  49. .id = UCLASS_MMC,
  50. .bind = pci_mmc_bind,
  51. .probe = pci_mmc_probe,
  52. .ops = &sdhci_ops,
  53. .priv_auto_alloc_size = sizeof(struct pci_mmc_priv),
  54. .platdata_auto_alloc_size = sizeof(struct pci_mmc_plat),
  55. };
  56. static struct pci_device_id mmc_supported[] = {
  57. { PCI_DEVICE_CLASS(PCI_CLASS_SYSTEM_SDHCI << 8, 0xffff00) },
  58. {},
  59. };
  60. U_BOOT_PCI_DEVICE(pci_mmc, mmc_supported);