blob: 6db89779ba3c1fada496030f533e533bc9a24262 [file] [log] [blame]
Simon Glass91785f72015-01-27 22:13:39 -07001/*
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 Glassddb3ac32017-04-09 18:38:21 -06009#include <dm.h>
Simon Glass91785f72015-01-27 22:13:39 -070010#include <errno.h>
11#include <malloc.h>
Simon Glassddb3ac32017-04-09 18:38:21 -060012#include <mapmem.h>
Simon Glass91785f72015-01-27 22:13:39 -070013#include <sdhci.h>
14#include <asm/pci.h>
15
Simon Glassddb3ac32017-04-09 18:38:21 -060016struct pci_mmc_plat {
17 struct mmc_config cfg;
18 struct mmc mmc;
19};
20
21struct pci_mmc_priv {
22 struct sdhci_host host;
23 void *base;
24};
25
26static int pci_mmc_probe(struct udevice *dev)
Simon Glass91785f72015-01-27 22:13:39 -070027{
Simon Glassddb3ac32017-04-09 18:38:21 -060028 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;
32 u32 ioaddr;
Simon Glass91785f72015-01-27 22:13:39 -070033 int ret;
Simon Glass91785f72015-01-27 22:13:39 -070034
Simon Glassddb3ac32017-04-09 18:38:21 -060035 dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &ioaddr);
36 host->ioaddr = map_sysmem(ioaddr, 0);
37 host->name = dev->name;
38 ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
39 if (ret)
40 return ret;
41 host->mmc = &plat->mmc;
42 host->mmc->priv = &priv->host;
43 host->mmc->dev = dev;
44 upriv->mmc = host->mmc;
Simon Glass91785f72015-01-27 22:13:39 -070045
Simon Glassddb3ac32017-04-09 18:38:21 -060046 return sdhci_probe(dev);
Simon Glass91785f72015-01-27 22:13:39 -070047}
Simon Glassddb3ac32017-04-09 18:38:21 -060048
49static int pci_mmc_bind(struct udevice *dev)
50{
51 struct pci_mmc_plat *plat = dev_get_platdata(dev);
52
53 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
54}
55
56U_BOOT_DRIVER(pci_mmc) = {
57 .name = "pci_mmc",
58 .id = UCLASS_MMC,
59 .bind = pci_mmc_bind,
60 .probe = pci_mmc_probe,
61 .ops = &sdhci_ops,
62 .priv_auto_alloc_size = sizeof(struct pci_mmc_priv),
63 .platdata_auto_alloc_size = sizeof(struct pci_mmc_plat),
64};
65
66static struct pci_device_id mmc_supported[] = {
67 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT_SDIO) },
68 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT_SD) },
69 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT_EMMC2) },
70 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_SDIO) },
71 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_SDIO_0) },
72 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_SDIO_1) },
73 {},
74};
75
76U_BOOT_PCI_DEVICE(pci_mmc, mmc_supported);