Simon Glass | 509805b | 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 | 0b61928 | 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 | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 15 | { |
| 16 | struct sdhci_host *mmc_host; |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 17 | u32 iobase; |
| 18 | int ret; |
| 19 | int i; |
| 20 | |
Simon Glass | 0b61928 | 2015-11-29 13:18:08 -0700 | [diff] [blame] | 21 | for (i = 0; ; i++) { |
| 22 | struct udevice *dev; |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 23 | |
Simon Glass | 0b61928 | 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 | 509805b | 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 | a440561 | 2016-04-22 20:59:31 +0900 | [diff] [blame] | 31 | mmc_host->name = name; |
Simon Glass | 0b61928 | 2015-11-29 13:18:08 -0700 | [diff] [blame] | 32 | dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase); |
Simon Glass | 3ae7d55 | 2016-09-25 21:33:10 -0600 | [diff] [blame] | 33 | mmc_host->ioaddr = (void *)(ulong)iobase; |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 34 | mmc_host->quirks = 0; |
Stefan Herbrechtsmeier | bc47e0e | 2017-01-17 15:58:48 +0100 | [diff] [blame^] | 35 | mmc_host->max_clk = 0; |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 36 | ret = add_sdhci(mmc_host, 0, 0); |
| 37 | if (ret) |
| 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | return 0; |
| 42 | } |