blob: e39b476834e650d187cfa25278ac48e7cfe87232 [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
Bin Mengda2364c2017-06-26 16:36:15 -070014int pci_mmc_init(const char *name, struct pci_device_id *mmc_supported)
Simon Glass91785f72015-01-27 22:13:39 -070015{
Bin Mengda2364c2017-06-26 16:36:15 -070016 struct sdhci_host *mmc_host;
17 u32 iobase;
Simon Glass91785f72015-01-27 22:13:39 -070018 int ret;
Bin Mengda2364c2017-06-26 16:36:15 -070019 int i;
Simon Glass91785f72015-01-27 22:13:39 -070020
Bin Mengda2364c2017-06-26 16:36:15 -070021 for (i = 0; ; i++) {
22 struct udevice *dev;
Simon Glass91785f72015-01-27 22:13:39 -070023
Bin Mengda2364c2017-06-26 16:36:15 -070024 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 *)(ulong)iobase;
34 mmc_host->quirks = 0;
35 mmc_host->max_clk = 0;
36 ret = add_sdhci(mmc_host, 0, 0);
37 if (ret)
38 return ret;
39 }
40
41 return 0;
Simon Glass91785f72015-01-27 22:13:39 -070042}