Debian Codegraph @

src/commonlib/storage/pci_sdhci.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #include <commonlib/sdhci.h>
4 #include <device/pci.h>
5 #include <device/pci_def.h>
6 #include <device/pci_ops.h>
7 #include <stdint.h>
8
9 #include "sd_mmc.h"
10 #include "storage.h"
11
12 /* Initialize an SDHCI port */
13 int sdhci_controller_init(struct sdhci_ctrlr *sdhci_ctrlr, void *ioaddr)
14 {
15 sdhci_ctrlr->ioaddr = ioaddr;
16 return add_sdhci(sdhci_ctrlr);
17 }
18
19 struct sd_mmc_ctrlr *new_mem_sdhci_controller(void *ioaddr,
20 int (*pre_init_func)(struct sdhci_ctrlr *host))
21 {
22 static bool sdhci_init_done;
23 static struct sdhci_ctrlr sdhci_ctrlr = {0};
24
25 if (sdhci_init_done == true) {
26 sdhc_error("Error: SDHCI is already initialized.\n");
27 return NULL;
28 }
29
30 sdhci_ctrlr.attach = pre_init_func;
31
32 if (sdhci_controller_init(&sdhci_ctrlr, ioaddr)) {
33 sdhc_error("Error: SDHCI initialization failed.\n");
34 return NULL;
35 }
36
37 sdhci_init_done = true;
38
39 return &sdhci_ctrlr.sd_mmc_ctrlr;
40 }
41
42 struct sd_mmc_ctrlr *new_pci_sdhci_controller(pci_devfn_t dev)
43 {
44 uintptr_t addr;
45
46 if (!CONFIG(PCI))
47 return NULL;
48
49 addr = pci_s_read_config32(dev, PCI_BASE_ADDRESS_0);
50 if (addr == ((uint32_t)~0)) {
51 sdhc_error("Error: PCI SDHCI not found\n");
52 return NULL;
53 }
54
55 addr &= ~0xf;
56 return new_mem_sdhci_controller((void *)addr, NULL);
57 }