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> |
Simon Glass | b7c6bae | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 10 | #include <errno.h> |
| 11 | #include <malloc.h> |
Simon Glass | b7c6bae | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 12 | #include <mapmem.h> |
Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 13 | #include <sdhci.h> |
| 14 | #include <asm/pci.h> |
| 15 | |
Simon Glass | b7c6bae | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 16 | struct pci_mmc_plat { |
| 17 | struct mmc_config cfg; |
| 18 | struct mmc mmc; |
| 19 | }; |
| 20 | |
| 21 | struct pci_mmc_priv { |
| 22 | struct sdhci_host host; |
| 23 | void *base; |
| 24 | }; |
| 25 | |
| 26 | static int pci_mmc_probe(struct udevice *dev) |
Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 27 | { |
Simon Glass | b7c6bae | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 28 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 29 | struct pci_mmc_plat *plat = dev_get_platdata(dev); |
| 30 | struct pci_mmc_priv *priv = dev_get_priv(dev); |
| 31 | struct sdhci_host *host = &priv->host; |
Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 32 | int ret; |
Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 33 | |
Bernhard Messerklinger | 0851f34 | 2018-02-15 09:09:43 +0100 | [diff] [blame] | 34 | host->ioaddr = (void *)dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0, |
| 35 | PCI_REGION_MEM); |
Simon Glass | b7c6bae | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 36 | host->name = dev->name; |
| 37 | ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0); |
| 38 | if (ret) |
| 39 | return ret; |
| 40 | host->mmc = &plat->mmc; |
| 41 | host->mmc->priv = &priv->host; |
| 42 | host->mmc->dev = dev; |
| 43 | upriv->mmc = host->mmc; |
Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 44 | |
Simon Glass | b7c6bae | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 45 | return sdhci_probe(dev); |
Simon Glass | 91785f7 | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 46 | } |
Simon Glass | b7c6bae | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 47 | |
| 48 | static int pci_mmc_bind(struct udevice *dev) |
| 49 | { |
| 50 | struct pci_mmc_plat *plat = dev_get_platdata(dev); |
| 51 | |
| 52 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
| 53 | } |
| 54 | |
| 55 | U_BOOT_DRIVER(pci_mmc) = { |
| 56 | .name = "pci_mmc", |
| 57 | .id = UCLASS_MMC, |
| 58 | .bind = pci_mmc_bind, |
| 59 | .probe = pci_mmc_probe, |
| 60 | .ops = &sdhci_ops, |
| 61 | .priv_auto_alloc_size = sizeof(struct pci_mmc_priv), |
| 62 | .platdata_auto_alloc_size = sizeof(struct pci_mmc_plat), |
| 63 | }; |
| 64 | |
| 65 | static struct pci_device_id mmc_supported[] = { |
Bin Meng | a191cca | 2017-08-09 00:21:00 -0700 | [diff] [blame] | 66 | { PCI_DEVICE_CLASS(PCI_CLASS_SYSTEM_SDHCI << 8, 0xffff00) }, |
Simon Glass | b7c6bae | 2017-07-30 19:24:01 -0700 | [diff] [blame] | 67 | {}, |
| 68 | }; |
| 69 | |
| 70 | U_BOOT_PCI_DEVICE(pci_mmc, mmc_supported); |