coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
sd_mmc_ctrlr.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Controller independent definitions
4  */
5 #ifndef __COMMONLIB_SD_MMC_CTRLR_H__
6 #define __COMMONLIB_SD_MMC_CTRLR_H__
7 
8 #include <stdint.h>
9 
10 /* Error values returned by the storage drivers */
11 #define CARD_UNUSABLE_ERR -17 /* Unusable Card */
12 #define CARD_COMM_ERR -18 /* Communications Error */
13 #define CARD_TIMEOUT -19
14 #define CARD_IN_PROGRESS -20 /* operation is in progress */
15 
16 /* MMC status in CBMEM_ID_MMC_STATUS */
17 enum {
22 };
23 
24 struct mmc_command {
26 
27 /* Common commands */
28 #define MMC_CMD_GO_IDLE_STATE 0
29 #define MMC_CMD_SEND_OP_COND 1
30 #define MMC_CMD_ALL_SEND_CID 2
31 #define MMC_CMD_SET_DSR 4
32 #define MMC_CMD_SELECT_CARD 7
33 #define MMC_CMD_SEND_CSD 9
34 #define MMC_CMD_SEND_CID 10
35 #define MMC_CMD_STOP_TRANSMISSION 12
36 #define MMC_CMD_SEND_STATUS 13
37 #define MMC_CMD_SET_BLOCKLEN 16
38 #define MMC_CMD_READ_SINGLE_BLOCK 17
39 #define MMC_CMD_READ_MULTIPLE_BLOCK 18
40 #define MMC_CMD_WRITE_SINGLE_BLOCK 24
41 #define MMC_CMD_WRITE_MULTIPLE_BLOCK 25
42 #define MMC_CMD_APP_CMD 55
43 
44 /* MMC specific commands */
45 #define MMC_CMD_SET_RELATIVE_ADDR 3
46 #define MMC_CMD_SWITCH 6
47 #define MMC_CMD_SEND_EXT_CSD 8
48 #define MMC_CMD_AUTO_TUNING_SEQUENCE 21
49 #define MMC_CMD_ERASE_GROUP_START 35
50 #define MMC_CMD_ERASE_GROUP_END 36
51 #define MMC_CMD_ERASE 38
52 #define MMC_CMD_SPI_READ_OCR 58
53 #define MMC_CMD_SPI_CRC_ON_OFF 59
54 
55 /* SD specific commands */
56 #define SD_CMD_SEND_RELATIVE_ADDR 3
57 #define SD_CMD_SWITCH_FUNC 6
58 #define SD_CMD_SEND_IF_COND 8
59 #define SD_CMD_ERASE_WR_BLK_START 32
60 #define SD_CMD_ERASE_WR_BLK_END 33
61 
62 /* SD specific APP commands */
63 #define SD_CMD_APP_SET_BUS_WIDTH 6
64 #define SD_CMD_APP_SEND_OP_COND 41
65 #define SD_CMD_APP_SEND_SCR 51
66 
68 
69 #define CARD_RSP_PRESENT (1 << 0)
70 #define CARD_RSP_136 (1 << 1) /* 136 bit response */
71 #define CARD_RSP_CRC (1 << 2) /* expect valid crc */
72 #define CARD_RSP_BUSY (1 << 3) /* card may send busy */
73 #define CARD_RSP_OPCODE (1 << 4) /* response contains opcode */
74 
75 #define CARD_RSP_NONE (0)
76 #define CARD_RSP_R1 (CARD_RSP_PRESENT|CARD_RSP_CRC|CARD_RSP_OPCODE)
77 #define CARD_RSP_R1b (CARD_RSP_PRESENT|CARD_RSP_CRC|CARD_RSP_OPCODE| \
78  CARD_RSP_BUSY)
79 #define CARD_RSP_R2 (CARD_RSP_PRESENT|CARD_RSP_136|CARD_RSP_CRC)
80 #define CARD_RSP_R3 (CARD_RSP_PRESENT)
81 #define CARD_RSP_R4 (CARD_RSP_PRESENT)
82 #define CARD_RSP_R5 (CARD_RSP_PRESENT|CARD_RSP_CRC|CARD_RSP_OPCODE)
83 #define CARD_RSP_R6 (CARD_RSP_PRESENT|CARD_RSP_CRC|CARD_RSP_OPCODE)
84 #define CARD_RSP_R7 (CARD_RSP_PRESENT|CARD_RSP_CRC|CARD_RSP_OPCODE)
85 
87 
88 #define MMC_TRIM_ARG 0x1
89 #define MMC_SECURE_ERASE_ARG 0x80000000
90 
93 
94 #define CMD_FLAG_IGNORE_INHIBIT 1
95 };
96 
97 #define SD_SWITCH_CHECK 0
98 #define SD_SWITCH_SWITCH 1
99 
100 #define SD_DATA_4BIT 0x00040000
101 
102 /* SCR definitions in different words */
103 #define SD_HIGHSPEED_BUSY 0x00020000
104 #define SD_HIGHSPEED_SUPPORTED 0x00020000
105 
106 struct mmc_data {
107  union {
108  char *dest;
109  const char *src;
110  };
112 
113 #define DATA_FLAG_READ 1
114 #define DATA_FLAG_WRITE 2
115 
118 };
119 
120 struct sd_mmc_ctrlr {
121  int (*send_cmd)(struct sd_mmc_ctrlr *ctrlr,
122  struct mmc_command *cmd, struct mmc_data *data);
123  void (*set_ios)(struct sd_mmc_ctrlr *ctrlr);
124  void (*tuning_start)(struct sd_mmc_ctrlr *ctrlr, int retune);
125  int (*is_tuning_complete)(struct sd_mmc_ctrlr *ctrlr, int *successful);
126 
128  unsigned int version;
130 
131 #define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */
132 #define MMC_VDD_20_21 0x00000100 /* VDD voltage 2.0 ~ 2.1 */
133 #define MMC_VDD_21_22 0x00000200 /* VDD voltage 2.1 ~ 2.2 */
134 #define MMC_VDD_22_23 0x00000400 /* VDD voltage 2.2 ~ 2.3 */
135 #define MMC_VDD_23_24 0x00000800 /* VDD voltage 2.3 ~ 2.4 */
136 #define MMC_VDD_24_25 0x00001000 /* VDD voltage 2.4 ~ 2.5 */
137 #define MMC_VDD_25_26 0x00002000 /* VDD voltage 2.5 ~ 2.6 */
138 #define MMC_VDD_26_27 0x00004000 /* VDD voltage 2.6 ~ 2.7 */
139 #define MMC_VDD_27_28 0x00008000 /* VDD voltage 2.7 ~ 2.8 */
140 #define MMC_VDD_28_29 0x00010000 /* VDD voltage 2.8 ~ 2.9 */
141 #define MMC_VDD_29_30 0x00020000 /* VDD voltage 2.9 ~ 3.0 */
142 #define MMC_VDD_30_31 0x00040000 /* VDD voltage 3.0 ~ 3.1 */
143 #define MMC_VDD_31_32 0x00080000 /* VDD voltage 3.1 ~ 3.2 */
144 #define MMC_VDD_32_33 0x00100000 /* VDD voltage 3.2 ~ 3.3 */
145 #define MMC_VDD_33_34 0x00200000 /* VDD voltage 3.3 ~ 3.4 */
146 #define MMC_VDD_34_35 0x00400000 /* VDD voltage 3.4 ~ 3.5 */
147 #define MMC_VDD_35_36 0x00800000 /* VDD voltage 3.5 ~ 3.6 */
148 
149 #define MMC_VDD_165_195_SHIFT 7
150 
151  uint32_t clock_base; /* Controller's base clock */
154  uint32_t request_hz; /* Desired clock frequency */
155  uint32_t bus_hz; /* Actual bus clock frequency */
156 
157 #define CLOCK_KHZ 1000
158 #define CLOCK_MHZ (1000 * CLOCK_KHZ)
159 #define CLOCK_20MHZ (20 * CLOCK_MHZ)
160 #define CLOCK_25MHZ (25 * CLOCK_MHZ)
161 #define CLOCK_26MHZ (26 * CLOCK_MHZ)
162 #define CLOCK_50MHZ (50 * CLOCK_MHZ)
163 #define CLOCK_52MHZ (52 * CLOCK_MHZ)
164 #define CLOCK_200MHZ (200 * CLOCK_MHZ)
165 
168 
169 /* Generic controller & driver capabilities. Controller specific capabilities
170  * start at 0x00010000
171  */
172 #define DRVR_CAP_4BIT 0x00000001
173 #define DRVR_CAP_8BIT 0x00000002
174 #define DRVR_CAP_AUTO_CMD12 0x00000004
175 #define DRVR_CAP_HC 0x00000008
176 #define DRVR_CAP_HS 0x00000010
177 #define DRVR_CAP_HS52 0x00000020
178 #define DRVR_CAP_HS200 0x00000040
179 #define DRVR_CAP_HS400 0x00000080
180 #define DRVR_CAP_ENHANCED_STROBE 0x00000100
181 #define DRVR_CAP_REMOVABLE 0x00000200
182 #define DRVR_CAP_DMA_64BIT 0x00000400
183 #define DRVR_CAP_HS200_TUNING 0x00000800
184 
187 
188 #define BUS_TIMING_LEGACY 0
189 #define BUS_TIMING_MMC_HS 1
190 #define BUS_TIMING_SD_HS 2
191 #define BUS_TIMING_UHS_SDR12 3
192 #define BUS_TIMING_UHS_SDR25 4
193 #define BUS_TIMING_UHS_SDR50 5
194 #define BUS_TIMING_UHS_SDR104 6
195 #define BUS_TIMING_UHS_DDR50 7
196 #define BUS_TIMING_MMC_DDR52 8
197 #define BUS_TIMING_MMC_HS200 9
198 #define BUS_TIMING_MMC_HS400 10
199 #define BUS_TIMING_MMC_HS400ES 11
200 
204 };
205 
206 /* SOC specific routine to override ctrlr->caps and .voltages
207  *
208  * Set/clear the necessary DRVR_CAP_xxx bits in ctrlr->caps to specify the
209  * controllers capabilities and driver workarounds.
210  *
211  * Set/clear the necessary MMC_VDD_xxx bits in ctrlr->voltages to specify the
212  * controllers power support.
213  */
214 void soc_sd_mmc_controller_quirks(struct sd_mmc_ctrlr *ctrlr);
215 
216 /* Optional routines to support logging */
217 void sdhc_log_command(struct mmc_command *cmd);
218 void sdhc_log_command_issued(void);
219 void sdhc_log_response(uint32_t entries, uint32_t *response);
220 void sdhc_log_ret(int ret);
221 
222 #endif /* __COMMONLIB_SD_MMC_CTRLR_H__ */
void sdhc_log_command(struct mmc_command *cmd)
Definition: sdhci.c:264
void sdhc_log_command_issued(void)
Definition: sdhci.c:268
@ MMC_STATUS_CMD1_READY
Definition: sd_mmc_ctrlr.h:20
@ MMC_STATUS_CMD1_IN_PROGRESS
Definition: sd_mmc_ctrlr.h:21
@ MMC_STATUS_CMD1_READY_OR_IN_PROGRESS
Definition: sd_mmc_ctrlr.h:19
@ MMC_STATUS_NEED_RESET
Definition: sd_mmc_ctrlr.h:18
void soc_sd_mmc_controller_quirks(struct sd_mmc_ctrlr *ctrlr)
Definition: sdhci.c:671
void sdhc_log_response(uint32_t entries, uint32_t *response)
Definition: sdhci.c:272
void sdhc_log_ret(int ret)
Definition: sdhci.c:277
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
uint32_t response[4]
Definition: sd_mmc_ctrlr.h:91
uint32_t cmdarg
Definition: sd_mmc_ctrlr.h:86
uint16_t cmdidx
Definition: sd_mmc_ctrlr.h:25
uint32_t flags
Definition: sd_mmc_ctrlr.h:92
uint32_t resp_type
Definition: sd_mmc_ctrlr.h:67
char * dest
Definition: sd_mmc_ctrlr.h:108
uint32_t blocksize
Definition: sd_mmc_ctrlr.h:117
uint32_t flags
Definition: sd_mmc_ctrlr.h:111
const char * src
Definition: sd_mmc_ctrlr.h:109
uint32_t blocks
Definition: sd_mmc_ctrlr.h:116
void(* tuning_start)(struct sd_mmc_ctrlr *ctrlr, int retune)
Definition: sd_mmc_ctrlr.h:124
uint32_t f_min
Definition: sd_mmc_ctrlr.h:152
uint32_t f_max
Definition: sd_mmc_ctrlr.h:153
uint32_t voltages
Definition: sd_mmc_ctrlr.h:129
uint32_t udelay_wait_after_cmd
Definition: sd_mmc_ctrlr.h:203
unsigned int version
Definition: sd_mmc_ctrlr.h:128
uint32_t b_max
Definition: sd_mmc_ctrlr.h:185
uint32_t bus_width
Definition: sd_mmc_ctrlr.h:166
uint32_t bus_hz
Definition: sd_mmc_ctrlr.h:155
uint32_t mdelay_before_cmd0
Definition: sd_mmc_ctrlr.h:201
uint32_t caps
Definition: sd_mmc_ctrlr.h:167
int(* send_cmd)(struct sd_mmc_ctrlr *ctrlr, struct mmc_command *cmd, struct mmc_data *data)
Definition: sd_mmc_ctrlr.h:121
uint32_t timing
Definition: sd_mmc_ctrlr.h:186
uint32_t mdelay_after_cmd0
Definition: sd_mmc_ctrlr.h:202
int(* is_tuning_complete)(struct sd_mmc_ctrlr *ctrlr, int *successful)
Definition: sd_mmc_ctrlr.h:125
uint32_t clock_base
Definition: sd_mmc_ctrlr.h:151
uint32_t request_hz
Definition: sd_mmc_ctrlr.h:154
void(* set_ios)(struct sd_mmc_ctrlr *ctrlr)
Definition: sd_mmc_ctrlr.h:123
typedef void(X86APIP X86EMU_intrFuncs)(int num)