blob: 340eef6a1f38c49e400244a55d69f7c75ecfaedc [file] [log] [blame]
Simon Glass91785f72015-01-27 22:13:39 -07001/*
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
Simon Glass4abe8e42015-11-29 13:18:08 -070014int pci_mmc_init(const char *name, struct pci_device_id *mmc_supported)
Simon Glass91785f72015-01-27 22:13:39 -070015{
16 struct sdhci_host *mmc_host;
Simon Glass91785f72015-01-27 22:13:39 -070017 u32 iobase;
18 int ret;
19 int i;
20
Simon Glass4abe8e42015-11-29 13:18:08 -070021 for (i = 0; ; i++) {
22 struct udevice *dev;
Simon Glass91785f72015-01-27 22:13:39 -070023
Simon Glass4abe8e42015-11-29 13:18:08 -070024 ret = pci_find_device_id(mmc_supported, i, &dev);
25 if (ret)
26 return ret;
Simon Glass91785f72015-01-27 22:13:39 -070027 mmc_host = malloc(sizeof(struct sdhci_host));
28 if (!mmc_host)
29 return -ENOMEM;
30
Masahiro Yamadacacd1d22016-04-22 20:59:31 +090031 mmc_host->name = name;
Simon Glass4abe8e42015-11-29 13:18:08 -070032 dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase);
Simon Glass91785f72015-01-27 22:13:39 -070033 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}