xref: /openbmc/u-boot/drivers/mmc/pci_mmc.c (revision ad3098f7)
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 
8 #include <common.h>
9 #include <errno.h>
10 #include <malloc.h>
11 #include <sdhci.h>
12 #include <asm/pci.h>
13 
14 int pci_mmc_init(const char *name, struct pci_device_id *mmc_supported)
15 {
16 	struct sdhci_host *mmc_host;
17 	u32 iobase;
18 	int ret;
19 	int i;
20 
21 	for (i = 0; ; i++) {
22 		struct udevice *dev;
23 
24 		ret = pci_find_device_id(mmc_supported, i, &dev);
25 		if (ret)
26 			return ret;
27 		mmc_host = malloc(sizeof(struct sdhci_host));
28 		if (!mmc_host)
29 			return -ENOMEM;
30 
31 		mmc_host->name = name;
32 		dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase);
33 		mmc_host->ioaddr = (void *)iobase;
34 		mmc_host->quirks = 0;
35 		ret = add_sdhci(mmc_host, 0, 0);
36 		if (ret)
37 			return ret;
38 	}
39 
40 	return 0;
41 }
42