coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
early_mmc.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpi.h>
4 #include <cbmem.h>
7 #include <commonlib/sdhci.h>
8 #include <compiler.h>
9 #include <console/console.h>
10 #include <device/pci.h>
11 #include <intelblocks/mmc.h>
12 #include <soc/iomap.h>
13 #include <soc/pci_devs.h>
14 #include <string.h>
15 
17 {
18  uint32_t f_min, f_max;
19 
20  if (soc_get_mmc_frequencies(&f_min, &f_max) < 0) {
22  "MMC early init: failed to get mmc frequencies\n");
23  return;
24  }
25 
26  ctrlr->f_min = f_min;
27  ctrlr->f_max = f_max;
28 }
29 
30 static void enable_mmc_controller_bar(void)
31 {
33  PRERAM_MMC_BASE_ADDRESS);
36 }
37 
38 static void disable_mmc_controller_bar(void)
39 {
43 }
44 
46 {
47  int32_t *ms_cbmem;
48 
49  ms_cbmem = cbmem_add(CBMEM_ID_MMC_STATUS, sizeof(int));
50 
51  if (ms_cbmem == NULL) {
53  "%s: Failed to add early mmc wake status to cbmem!\n",
54  __func__);
55  return;
56  }
57 
58  *ms_cbmem = status;
59 }
60 
62 {
63  struct storage_media media;
64  struct sd_mmc_ctrlr *mmc_ctrlr;
65  struct sdhci_ctrlr *sdhci_ctrlr;
66  int err;
67 
68  if (acpi_is_wakeup_s3())
69  return -1;
70 
71  /* Configure mmc gpios */
72  if (soc_configure_mmc_gpios() < 0) {
74  "%s: MMC early init: failed to configure mmc gpios\n",
75  __func__);
76  return -1;
77  }
78  /* Setup pci bar */
80 
81  /* Initialize sdhci */
83  if (mmc_ctrlr == NULL)
84  goto out_err;
85 
86  sdhci_ctrlr = container_of(mmc_ctrlr, struct sdhci_ctrlr, sd_mmc_ctrlr);
87 
88  /* set emmc DLL tuning parameters */
89  if (set_mmc_dll(sdhci_ctrlr->ioaddr) < 0)
90  goto out_err;
91 
92  memset(&media, 0, sizeof(media));
93  media.ctrlr = mmc_ctrlr;
94  SET_BUS_WIDTH(mmc_ctrlr, 1);
95  /*
96  * Set clock to 1 so that the driver can choose minimum frequency
97  * possible
98  */
99  SET_CLOCK(mmc_ctrlr, 1);
100 
101  /* Reset emmc, send CMD0 */
102  if (sd_mmc_go_idle(&media))
103  goto out_err;
104 
105  /* Send CMD1 */
106  err = mmc_send_op_cond(&media);
107  if (err != 0 && err != CARD_IN_PROGRESS)
108  goto out_err;
109 
111 
113  return 0;
114 
115 out_err:
116 
118  return -1;
119 }
static int acpi_is_wakeup_s3(void)
Definition: acpi.h:9
void * memset(void *dstpp, int c, size_t len)
Definition: memset.c:12
void * cbmem_add(u32 id, u64 size)
Definition: imd_cbmem.c:144
#define CBMEM_ID_MMC_STATUS
Definition: cbmem_id.h:35
#define printk(level,...)
Definition: stdlib.h:16
int mmc_send_op_cond(struct storage_media *media)
Definition: mmc.c:45
static void disable_mmc_controller_bar(void)
Definition: early_mmc.c:38
static void enable_mmc_controller_bar(void)
Definition: early_mmc.c:30
int early_mmc_wake_hw(void)
Definition: early_mmc.c:61
static void set_early_mmc_wake_status(int32_t status)
Definition: early_mmc.c:45
void soc_sd_mmc_controller_quirks(struct sd_mmc_ctrlr *ctrlr)
Definition: early_mmc.c:16
#define container_of(ptr, type, member)
container_of - cast a member of a structure out to the containing structure
Definition: helpers.h:33
struct sd_mmc_ctrlr * new_pci_sdhci_controller(uint32_t dev)
Definition: pci_sdhci.c:40
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
static __always_inline void pci_write_config16(const struct device *dev, u16 reg, u16 val)
Definition: pci_ops.h:70
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define PCI_COMMAND_MASTER
Definition: pci_def.h:13
#define PCI_COMMAND_MEMORY
Definition: pci_def.h:12
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
#define PCI_COMMAND
Definition: pci_def.h:10
static struct storage_media media
Definition: sd_media.c:21
int sd_mmc_go_idle(struct storage_media *media)
Definition: sd_mmc.c:68
#define SET_BUS_WIDTH(ctrlr, width)
Definition: sd_mmc.h:15
#define SET_CLOCK(ctrlr, clock_hz)
Definition: sd_mmc.h:21
#define CARD_IN_PROGRESS
Definition: sd_mmc_ctrlr.h:14
#define PCH_DEV_EMMC
Definition: pci_devs.h:149
int soc_configure_mmc_gpios(void)
int soc_get_mmc_frequencies(uint32_t *f_min, uint32_t *f_max)
int set_mmc_dll(void *bar)
Definition: mmc.c:19
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
signed int int32_t
Definition: stdint.h:13
uint32_t f_min
Definition: sd_mmc_ctrlr.h:152
uint32_t f_max
Definition: sd_mmc_ctrlr.h:153
void * ioaddr
Definition: sdhci.h:37
struct sd_mmc_ctrlr * ctrlr
Definition: storage.h:63