Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015, Google, Inc |
| 4 | * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 828b725 | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 9 | #include <errno.h> |
| 10 | #include <malloc.h> |
Simon Glass | 828b725 | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 11 | #include <mapmem.h> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 12 | #include <sdhci.h> |
| 13 | #include <asm/pci.h> |
| 14 | |
Simon Glass | 828b725 | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 15 | struct pci_mmc_plat { |
| 16 | struct mmc_config cfg; |
| 17 | struct mmc mmc; |
| 18 | }; |
| 19 | |
| 20 | struct pci_mmc_priv { |
| 21 | struct sdhci_host host; |
| 22 | void *base; |
| 23 | }; |
| 24 | |
| 25 | static int pci_mmc_probe(struct udevice *dev) |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 26 | { |
Simon Glass | 828b725 | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 27 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 28 | struct pci_mmc_plat *plat = dev_get_platdata(dev); |
| 29 | struct pci_mmc_priv *priv = dev_get_priv(dev); |
| 30 | struct sdhci_host *host = &priv->host; |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 31 | int ret; |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 32 | |
Bernhard Messerklinger | da5cfec | 2018-02-15 09:09:43 +0100 | [diff] [blame] | 33 | host->ioaddr = (void *)dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0, |
| 34 | PCI_REGION_MEM); |
Simon Glass | 828b725 | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 35 | host->name = dev->name; |
| 36 | ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0); |
| 37 | if (ret) |
| 38 | return ret; |
| 39 | host->mmc = &plat->mmc; |
| 40 | host->mmc->priv = &priv->host; |
| 41 | host->mmc->dev = dev; |
| 42 | upriv->mmc = host->mmc; |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 43 | |
Simon Glass | 828b725 | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 44 | return sdhci_probe(dev); |
| 45 | } |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 46 | |
Simon Glass | 828b725 | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 47 | static int pci_mmc_bind(struct udevice *dev) |
| 48 | { |
| 49 | struct pci_mmc_plat *plat = dev_get_platdata(dev); |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 50 | |
Simon Glass | 828b725 | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 51 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 52 | } |
Simon Glass | 828b725 | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 53 | |
| 54 | U_BOOT_DRIVER(pci_mmc) = { |
| 55 | .name = "pci_mmc", |
| 56 | .id = UCLASS_MMC, |
| 57 | .bind = pci_mmc_bind, |
| 58 | .probe = pci_mmc_probe, |
| 59 | .ops = &sdhci_ops, |
| 60 | .priv_auto_alloc_size = sizeof(struct pci_mmc_priv), |
| 61 | .platdata_auto_alloc_size = sizeof(struct pci_mmc_plat), |
| 62 | }; |
| 63 | |
| 64 | static struct pci_device_id mmc_supported[] = { |
Bin Meng | 77520f8 | 2017-08-09 00:21:00 -0700 | [diff] [blame] | 65 | { PCI_DEVICE_CLASS(PCI_CLASS_SYSTEM_SDHCI << 8, 0xffff00) }, |
Simon Glass | 828b725 | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 66 | {}, |
| 67 | }; |
| 68 | |
| 69 | U_BOOT_PCI_DEVICE(pci_mmc, mmc_supported); |