soc/intel/alderlake/acpi.c: Don't look up coreboot CPU index
[coreboot.git] / src / commonlib / storage / pci_sdhci.c
blobe180d9f48ebb09eb1f66216749a8e9fb5ba3683a
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #include <commonlib/sdhci.h>
4 #include <device/pci.h>
5 #include <device/pci_ops.h>
6 #include <stdint.h>
7 #include <string.h>
9 #include "sd_mmc.h"
10 #include "storage.h"
12 /* Initialize an SDHCI port */
13 int sdhci_controller_init(struct sdhci_ctrlr *sdhci_ctrlr, void *ioaddr)
15 memset(sdhci_ctrlr, 0, sizeof(*sdhci_ctrlr));
16 sdhci_ctrlr->ioaddr = ioaddr;
17 return add_sdhci(sdhci_ctrlr);
20 struct sd_mmc_ctrlr *new_mem_sdhci_controller(void *ioaddr)
22 static bool sdhci_init_done;
23 static struct sdhci_ctrlr sdhci_ctrlr;
25 if (sdhci_init_done == true) {
26 sdhc_error("Error: SDHCI is already initialized.\n");
27 return NULL;
30 if (sdhci_controller_init(&sdhci_ctrlr, ioaddr)) {
31 sdhc_error("Error: SDHCI initialization failed.\n");
32 return NULL;
35 sdhci_init_done = true;
37 return &sdhci_ctrlr.sd_mmc_ctrlr;
40 struct sd_mmc_ctrlr *new_pci_sdhci_controller(pci_devfn_t dev)
42 uint32_t addr;
44 addr = pci_s_read_config32(dev, PCI_BASE_ADDRESS_0);
45 if (addr == ((uint32_t)~0)) {
46 sdhc_error("Error: PCI SDHCI not found\n");
47 return NULL;
50 addr &= ~0xf;
51 return new_mem_sdhci_controller((void *)addr);