aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShelley Chen <shchen@google.com>2023-01-30 14:46:38 -0800
committerShelley Chen <shchen@google.com>2023-02-08 16:59:28 +0000
commit8c692d7dfaede453d8c974819c3f3bec67b24e55 (patch)
tree6ae39906a9978eeab260dc4e1c19ee3b8b97b708 /src
parent3ecf377e305e1a026ddfa66adf800a28993f4075 (diff)
commonlib/storage: Add attach callback to sdhci_ctrlr
Adding a attach callback function pointer in case a platform needs to execute anything before the standard initialization of the sdhci mem controller. BUG=b:254092907 BRANCH=None TEST=emerge-herobrine coreboot Change-Id: I0f37ec09d083922cad5ecd3c47b184cf3311fe2d Signed-off-by: Shelley Chen <shchen@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/72633 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Douglas Anderson <dianders@chromium.org>
Diffstat (limited to 'src')
-rw-r--r--src/commonlib/include/commonlib/sdhci.h9
-rw-r--r--src/commonlib/storage/pci_sdhci.c10
-rw-r--r--src/commonlib/storage/sdhci.c10
3 files changed, 24 insertions, 5 deletions
diff --git a/src/commonlib/include/commonlib/sdhci.h b/src/commonlib/include/commonlib/sdhci.h
index f9a47b3832..e261c94932 100644
--- a/src/commonlib/include/commonlib/sdhci.h
+++ b/src/commonlib/include/commonlib/sdhci.h
@@ -46,6 +46,12 @@ struct sdhci_ctrlr {
/* Number of ADMA descriptors currently in the array. */
int adma_desc_count;
+
+ /*
+ * Point to function to run before running initialization.
+ * This would include anything non-standard.
+ */
+ int (*attach)(struct sdhci_ctrlr *ctrlr);
};
int add_sdhci(struct sdhci_ctrlr *sdhci_ctrlr);
@@ -57,6 +63,7 @@ void sdhci_display_setup(struct sdhci_ctrlr *sdhci_ctrlr);
struct sd_mmc_ctrlr *new_pci_sdhci_controller(uint32_t dev);
/* Add SDHCI controller with memory address */
-struct sd_mmc_ctrlr *new_mem_sdhci_controller(void *ioaddr);
+struct sd_mmc_ctrlr *new_mem_sdhci_controller(void *ioaddr,
+ int (*pre_init_func)(struct sdhci_ctrlr *host));
#endif /* __COMMONLIB_SDHCI_H__ */
diff --git a/src/commonlib/storage/pci_sdhci.c b/src/commonlib/storage/pci_sdhci.c
index 2f9b648130..de9dd1b55c 100644
--- a/src/commonlib/storage/pci_sdhci.c
+++ b/src/commonlib/storage/pci_sdhci.c
@@ -12,21 +12,23 @@
/* Initialize an SDHCI port */
int sdhci_controller_init(struct sdhci_ctrlr *sdhci_ctrlr, void *ioaddr)
{
- memset(sdhci_ctrlr, 0, sizeof(*sdhci_ctrlr));
sdhci_ctrlr->ioaddr = ioaddr;
return add_sdhci(sdhci_ctrlr);
}
-struct sd_mmc_ctrlr *new_mem_sdhci_controller(void *ioaddr)
+struct sd_mmc_ctrlr *new_mem_sdhci_controller(void *ioaddr,
+ int (*pre_init_func)(struct sdhci_ctrlr *host))
{
static bool sdhci_init_done;
- static struct sdhci_ctrlr sdhci_ctrlr;
+ static struct sdhci_ctrlr sdhci_ctrlr = {0};
if (sdhci_init_done == true) {
sdhc_error("Error: SDHCI is already initialized.\n");
return NULL;
}
+ sdhci_ctrlr.attach = pre_init_func;
+
if (sdhci_controller_init(&sdhci_ctrlr, ioaddr)) {
sdhc_error("Error: SDHCI initialization failed.\n");
return NULL;
@@ -48,5 +50,5 @@ struct sd_mmc_ctrlr *new_pci_sdhci_controller(pci_devfn_t dev)
}
addr &= ~0xf;
- return new_mem_sdhci_controller((void *)addr);
+ return new_mem_sdhci_controller((void *)addr, NULL);
}
diff --git a/src/commonlib/storage/sdhci.c b/src/commonlib/storage/sdhci.c
index 3a01f62af1..882920d6a4 100644
--- a/src/commonlib/storage/sdhci.c
+++ b/src/commonlib/storage/sdhci.c
@@ -585,6 +585,16 @@ static int sdhci_pre_init(struct sdhci_ctrlr *sdhci_ctrlr)
struct sd_mmc_ctrlr *ctrlr = &sdhci_ctrlr->sd_mmc_ctrlr;
unsigned int caps, caps_1;
+ /*
+ * If the device needs to do anything non-standard before
+ * sdhci initialization, run it here.
+ */
+ if (sdhci_ctrlr->attach) {
+ int rv = sdhci_ctrlr->attach(sdhci_ctrlr);
+ if (rv)
+ return rv;
+ }
+
/* Get controller version and capabilities */
ctrlr->version = sdhci_readw(sdhci_ctrlr, SDHCI_HOST_VERSION) & 0xff;
caps = sdhci_readl(sdhci_ctrlr, SDHCI_CAPABILITIES);