Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 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 | |
Simon Glass | 4abe8e4 | 2015-11-29 13:18:08 -0700 | [diff] [blame] | 14 | int pci_mmc_init(const char *name, struct pci_device_id *mmc_supported) |
Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 15 | { |
| 16 | struct sdhci_host *mmc_host; |
Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 17 | u32 iobase; |
| 18 | int ret; |
| 19 | int i; |
| 20 | |
Simon Glass | 4abe8e4 | 2015-11-29 13:18:08 -0700 | [diff] [blame] | 21 | for (i = 0; ; i++) { |
| 22 | struct udevice *dev; |
Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 23 | |
Simon Glass | 4abe8e4 | 2015-11-29 13:18:08 -0700 | [diff] [blame] | 24 | ret = pci_find_device_id(mmc_supported, i, &dev); |
| 25 | if (ret) |
| 26 | return ret; |
Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 27 | mmc_host = malloc(sizeof(struct sdhci_host)); |
| 28 | if (!mmc_host) |
| 29 | return -ENOMEM; |
| 30 | |
Masahiro Yamada | cacd1d2 | 2016-04-22 20:59:31 +0900 | [diff] [blame^] | 31 | mmc_host->name = name; |
Simon Glass | 4abe8e4 | 2015-11-29 13:18:08 -0700 | [diff] [blame] | 32 | dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase); |
Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 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 | } |