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 | |
| 14 | int pci_mmc_init(const char *name, struct pci_device_id *mmc_supported, |
| 15 | int num_ids) |
| 16 | { |
| 17 | struct sdhci_host *mmc_host; |
| 18 | pci_dev_t devbusfn; |
| 19 | u32 iobase; |
| 20 | int ret; |
| 21 | int i; |
| 22 | |
| 23 | for (i = 0; i < num_ids; i++) { |
| 24 | devbusfn = pci_find_devices(mmc_supported, i); |
| 25 | if (devbusfn == -1) |
| 26 | return -ENODEV; |
| 27 | |
| 28 | mmc_host = malloc(sizeof(struct sdhci_host)); |
| 29 | if (!mmc_host) |
| 30 | return -ENOMEM; |
| 31 | |
| 32 | mmc_host->name = (char *)name; |
| 33 | pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_0, &iobase); |
| 34 | mmc_host->ioaddr = (void *)iobase; |
| 35 | mmc_host->quirks = 0; |
| 36 | ret = add_sdhci(mmc_host, 0, 0); |
| 37 | if (ret) |
| 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | return 0; |
| 42 | } |