]> Git Repo - qemu.git/blob - hw/sd/sdhci-internal.h
sdhci: add support for v3 capabilities
[qemu.git] / hw / sd / sdhci-internal.h
1 /*
2  * SD Association Host Standard Specification v2.0 controller emulation
3  *
4  * Copyright (c) 2011 Samsung Electronics Co., Ltd.
5  * Mitsyanko Igor <[email protected]>
6  * Peter A.G. Crosthwaite <[email protected]>
7  *
8  * Based on MMC controller for Samsung S5PC1xx-based board emulation
9  * by Alexey Merkulov and Vladimir Monakhov.
10  *
11  * This program is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU General Public License as published by the
13  * Free Software Foundation; either version 2 of the License, or (at your
14  * option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, see <http://www.gnu.org/licenses/>.
23  */
24 #ifndef SDHCI_INTERNAL_H
25 #define SDHCI_INTERNAL_H
26
27 #include "hw/registerfields.h"
28
29 /* R/W SDMA System Address register 0x0 */
30 #define SDHC_SYSAD                     0x00
31
32 /* R/W Host DMA Buffer Boundary and Transfer Block Size Register 0x0 */
33 #define SDHC_BLKSIZE                   0x04
34
35 /* R/W Blocks count for current transfer 0x0 */
36 #define SDHC_BLKCNT                    0x06
37
38 /* R/W Command Argument Register 0x0 */
39 #define SDHC_ARGUMENT                  0x08
40
41 /* R/W Transfer Mode Setting Register 0x0 */
42 #define SDHC_TRNMOD                    0x0C
43 #define SDHC_TRNS_DMA                  0x0001
44 #define SDHC_TRNS_BLK_CNT_EN           0x0002
45 #define SDHC_TRNS_ACMD12               0x0004
46 #define SDHC_TRNS_ACMD23               0x0008 /* since v3 */
47 #define SDHC_TRNS_READ                 0x0010
48 #define SDHC_TRNS_MULTI                0x0020
49 #define SDHC_TRNMOD_MASK               0x0037
50
51 /* R/W Command Register 0x0 */
52 #define SDHC_CMDREG                    0x0E
53 #define SDHC_CMD_RSP_WITH_BUSY         (3 << 0)
54 #define SDHC_CMD_DATA_PRESENT          (1 << 5)
55 #define SDHC_CMD_SUSPEND               (1 << 6)
56 #define SDHC_CMD_RESUME                (1 << 7)
57 #define SDHC_CMD_ABORT                 ((1 << 6)|(1 << 7))
58 #define SDHC_CMD_TYPE_MASK             ((1 << 6)|(1 << 7))
59 #define SDHC_COMMAND_TYPE(x)           ((x) & SDHC_CMD_TYPE_MASK)
60
61 /* ROC Response Register 0 0x0 */
62 #define SDHC_RSPREG0                   0x10
63 /* ROC Response Register 1 0x0 */
64 #define SDHC_RSPREG1                   0x14
65 /* ROC Response Register 2 0x0 */
66 #define SDHC_RSPREG2                   0x18
67 /* ROC Response Register 3 0x0 */
68 #define SDHC_RSPREG3                   0x1C
69
70 /* R/W Buffer Data Register 0x0 */
71 #define SDHC_BDATA                     0x20
72
73 /* R/ROC Present State Register 0x000A0000 */
74 #define SDHC_PRNSTS                    0x24
75 #define SDHC_CMD_INHIBIT               0x00000001
76 #define SDHC_DATA_INHIBIT              0x00000002
77 #define SDHC_DAT_LINE_ACTIVE           0x00000004
78 #define SDHC_DOING_WRITE               0x00000100
79 #define SDHC_DOING_READ                0x00000200
80 #define SDHC_SPACE_AVAILABLE           0x00000400
81 #define SDHC_DATA_AVAILABLE            0x00000800
82 #define SDHC_CARD_PRESENT              0x00010000
83 #define SDHC_CARD_DETECT               0x00040000
84 #define SDHC_WRITE_PROTECT             0x00080000
85 #define TRANSFERRING_DATA(x)           \
86     ((x) & (SDHC_DOING_READ | SDHC_DOING_WRITE))
87
88 /* R/W Host control Register 0x0 */
89 #define SDHC_HOSTCTL                   0x28
90 #define SDHC_CTRL_LED                  0x01
91 #define SDHC_CTRL_DATATRANSFERWIDTH    0x02 /* SD mode only */
92 #define SDHC_CTRL_HIGH_SPEED           0x04
93 #define SDHC_CTRL_DMA_CHECK_MASK       0x18
94 #define SDHC_CTRL_SDMA                 0x00
95 #define SDHC_CTRL_ADMA1_32             0x08 /* NOT ALLOWED since v2 */
96 #define SDHC_CTRL_ADMA2_32             0x10
97 #define SDHC_CTRL_ADMA2_64             0x18
98 #define SDHC_DMA_TYPE(x)               ((x) & SDHC_CTRL_DMA_CHECK_MASK)
99 #define SDHC_CTRL_4BITBUS              0x02
100 #define SDHC_CTRL_8BITBUS              0x20
101 #define SDHC_CTRL_CDTEST_INS           0x40
102 #define SDHC_CTRL_CDTEST_EN            0x80
103
104 /* R/W Power Control Register 0x0 */
105 #define SDHC_PWRCON                    0x29
106 #define SDHC_POWER_ON                  (1 << 0)
107 FIELD(SDHC_PWRCON, BUS_VOLTAGE,        1, 3);
108
109 /* R/W Block Gap Control Register 0x0 */
110 #define SDHC_BLKGAP                    0x2A
111 #define SDHC_STOP_AT_GAP_REQ           0x01
112 #define SDHC_CONTINUE_REQ              0x02
113
114 /* R/W WakeUp Control Register 0x0 */
115 #define SDHC_WAKCON                    0x2B
116 #define SDHC_WKUP_ON_INS               (1 << 1)
117 #define SDHC_WKUP_ON_RMV               (1 << 2)
118
119 /* CLKCON */
120 #define SDHC_CLKCON                    0x2C
121 #define SDHC_CLOCK_INT_STABLE          0x0002
122 #define SDHC_CLOCK_INT_EN              0x0001
123 #define SDHC_CLOCK_SDCLK_EN            (1 << 2)
124 #define SDHC_CLOCK_CHK_MASK            0x0007
125 #define SDHC_CLOCK_IS_ON(x)            \
126     (((x) & SDHC_CLOCK_CHK_MASK) == SDHC_CLOCK_CHK_MASK)
127
128 /* R/W Timeout Control Register 0x0 */
129 #define SDHC_TIMEOUTCON                0x2E
130 FIELD(SDHC_TIMEOUTCON, COUNTER,        0, 4);
131
132 /* R/W Software Reset Register 0x0 */
133 #define SDHC_SWRST                     0x2F
134 #define SDHC_RESET_ALL                 0x01
135 #define SDHC_RESET_CMD                 0x02
136 #define SDHC_RESET_DATA                0x04
137
138 /* ROC/RW1C Normal Interrupt Status Register 0x0 */
139 #define SDHC_NORINTSTS                 0x30
140 #define SDHC_NIS_ERR                   0x8000
141 #define SDHC_NIS_CMDCMP                0x0001
142 #define SDHC_NIS_TRSCMP                0x0002
143 #define SDHC_NIS_BLKGAP                0x0004
144 #define SDHC_NIS_DMA                   0x0008
145 #define SDHC_NIS_WBUFRDY               0x0010
146 #define SDHC_NIS_RBUFRDY               0x0020
147 #define SDHC_NIS_INSERT                0x0040
148 #define SDHC_NIS_REMOVE                0x0080
149 #define SDHC_NIS_CARDINT               0x0100
150
151 /* ROC/RW1C Error Interrupt Status Register 0x0 */
152 #define SDHC_ERRINTSTS                 0x32
153 #define SDHC_EIS_CMDTIMEOUT            0x0001
154 #define SDHC_EIS_BLKGAP                0x0004
155 #define SDHC_EIS_CMDIDX                0x0008
156 #define SDHC_EIS_CMD12ERR              0x0100
157 #define SDHC_EIS_ADMAERR               0x0200
158
159 /* R/W Normal Interrupt Status Enable Register 0x0 */
160 #define SDHC_NORINTSTSEN               0x34
161 #define SDHC_NISEN_CMDCMP              0x0001
162 #define SDHC_NISEN_TRSCMP              0x0002
163 #define SDHC_NISEN_DMA                 0x0008
164 #define SDHC_NISEN_WBUFRDY             0x0010
165 #define SDHC_NISEN_RBUFRDY             0x0020
166 #define SDHC_NISEN_INSERT              0x0040
167 #define SDHC_NISEN_REMOVE              0x0080
168 #define SDHC_NISEN_CARDINT             0x0100
169
170 /* R/W Error Interrupt Status Enable Register 0x0 */
171 #define SDHC_ERRINTSTSEN               0x36
172 #define SDHC_EISEN_CMDTIMEOUT          0x0001
173 #define SDHC_EISEN_BLKGAP              0x0004
174 #define SDHC_EISEN_CMDIDX              0x0008
175 #define SDHC_EISEN_ADMAERR             0x0200
176
177 /* R/W Normal Interrupt Signal Enable Register 0x0 */
178 #define SDHC_NORINTSIGEN               0x38
179 #define SDHC_NORINTSIG_INSERT          (1 << 6)
180 #define SDHC_NORINTSIG_REMOVE          (1 << 7)
181
182 /* R/W Error Interrupt Signal Enable Register 0x0 */
183 #define SDHC_ERRINTSIGEN               0x3A
184
185 /* ROC Auto CMD12 error status register 0x0 */
186 #define SDHC_ACMD12ERRSTS              0x3C
187 FIELD(SDHC_ACMD12ERRSTS, TIMEOUT_ERR,  1, 1);
188 FIELD(SDHC_ACMD12ERRSTS, CRC_ERR,      2, 1);
189 FIELD(SDHC_ACMD12ERRSTS, INDEX_ERR,    4, 1);
190
191 /* HWInit Capabilities Register 0x05E80080 */
192 #define SDHC_CAPAB                     0x40
193 FIELD(SDHC_CAPAB, TOCLKFREQ,           0, 6);
194 FIELD(SDHC_CAPAB, TOUNIT,              7, 1);
195 FIELD(SDHC_CAPAB, BASECLKFREQ,         8, 8);
196 FIELD(SDHC_CAPAB, MAXBLOCKLENGTH,     16, 2);
197 FIELD(SDHC_CAPAB, EMBEDDED_8BIT,      18, 1); /* since v3 */
198 FIELD(SDHC_CAPAB, ADMA2,              19, 1); /* since v2 */
199 FIELD(SDHC_CAPAB, ADMA1,              20, 1); /* v1 only? */
200 FIELD(SDHC_CAPAB, HIGHSPEED,          21, 1);
201 FIELD(SDHC_CAPAB, SDMA,               22, 1);
202 FIELD(SDHC_CAPAB, SUSPRESUME,         23, 1);
203 FIELD(SDHC_CAPAB, V33,                24, 1);
204 FIELD(SDHC_CAPAB, V30,                25, 1);
205 FIELD(SDHC_CAPAB, V18,                26, 1);
206 FIELD(SDHC_CAPAB, BUS64BIT,           28, 1); /* since v2 */
207 FIELD(SDHC_CAPAB, ASYNC_INT,          29, 1); /* since v3 */
208 FIELD(SDHC_CAPAB, SLOT_TYPE,          30, 2); /* since v3 */
209 FIELD(SDHC_CAPAB, BUS_SPEED,          32, 3); /* since v3 */
210 FIELD(SDHC_CAPAB, DRIVER_STRENGTH,    36, 3); /* since v3 */
211 FIELD(SDHC_CAPAB, DRIVER_TYPE_A,      36, 1); /* since v3 */
212 FIELD(SDHC_CAPAB, DRIVER_TYPE_C,      37, 1); /* since v3 */
213 FIELD(SDHC_CAPAB, DRIVER_TYPE_D,      38, 1); /* since v3 */
214 FIELD(SDHC_CAPAB, TIMER_RETUNING,     40, 4); /* since v3 */
215 FIELD(SDHC_CAPAB, SDR50_TUNING,       45, 1); /* since v3 */
216 FIELD(SDHC_CAPAB, RETUNING_MODE,      46, 2); /* since v3 */
217 FIELD(SDHC_CAPAB, CLOCK_MULT,         48, 8); /* since v3 */
218
219 /* HWInit Maximum Current Capabilities Register 0x0 */
220 #define SDHC_MAXCURR                   0x48
221 FIELD(SDHC_MAXCURR, V33_VDD1,          0, 8);
222 FIELD(SDHC_MAXCURR, V30_VDD1,          8, 8);
223 FIELD(SDHC_MAXCURR, V18_VDD1,         16, 8);
224
225 /* W Force Event Auto CMD12 Error Interrupt Register 0x0000 */
226 #define SDHC_FEAER                     0x50
227 /* W Force Event Error Interrupt Register Error Interrupt 0x0000 */
228 #define SDHC_FEERR                     0x52
229
230 /* R/W ADMA Error Status Register 0x00 */
231 #define SDHC_ADMAERR                   0x54
232 #define SDHC_ADMAERR_LENGTH_MISMATCH   (1 << 2)
233 #define SDHC_ADMAERR_STATE_ST_STOP     (0 << 0)
234 #define SDHC_ADMAERR_STATE_ST_FDS      (1 << 0)
235 #define SDHC_ADMAERR_STATE_ST_TFR      (3 << 0)
236 #define SDHC_ADMAERR_STATE_MASK        (3 << 0)
237
238 /* R/W ADMA System Address Register 0x00 */
239 #define SDHC_ADMASYSADDR               0x58
240 #define SDHC_ADMA_ATTR_SET_LEN         (1 << 4)
241 #define SDHC_ADMA_ATTR_ACT_TRAN        (1 << 5)
242 #define SDHC_ADMA_ATTR_ACT_LINK        (3 << 4)
243 #define SDHC_ADMA_ATTR_INT             (1 << 2)
244 #define SDHC_ADMA_ATTR_END             (1 << 1)
245 #define SDHC_ADMA_ATTR_VALID           (1 << 0)
246 #define SDHC_ADMA_ATTR_ACT_MASK        ((1 << 4)|(1 << 5))
247
248 /* Slot interrupt status */
249 #define SDHC_SLOT_INT_STATUS            0xFC
250
251 /* HWInit Host Controller Version Register */
252 #define SDHC_HCVER                      0xFE
253 #define SDHC_HCVER_VENDOR               0x24
254
255 #define SDHC_REGISTERS_MAP_SIZE         0x100
256 #define SDHC_INSERTION_DELAY            (NANOSECONDS_PER_SECOND)
257 #define SDHC_TRANSFER_DELAY             100
258 #define SDHC_ADMA_DESCS_PER_DELAY       5
259 #define SDHC_CMD_RESPONSE               (3 << 0)
260
261 enum {
262     sdhc_not_stopped = 0, /* normal SDHC state */
263     sdhc_gap_read   = 1,  /* SDHC stopped at block gap during read operation */
264     sdhc_gap_write  = 2   /* SDHC stopped at block gap during write operation */
265 };
266
267 extern const VMStateDescription sdhci_vmstate;
268
269
270 #define ESDHC_MIX_CTRL                  0x48
271 #define ESDHC_VENDOR_SPEC               0xc0
272 #define ESDHC_DLL_CTRL                  0x60
273
274 #define ESDHC_TUNING_CTRL               0xcc
275 #define ESDHC_TUNE_CTRL_STATUS          0x68
276 #define ESDHC_WTMK_LVL                  0x44
277
278 /* Undocumented register used by guests working around erratum ERR004536 */
279 #define ESDHC_UNDOCUMENTED_REG27        0x6c
280
281 #define ESDHC_CTRL_4BITBUS              (0x1 << 1)
282 #define ESDHC_CTRL_8BITBUS              (0x2 << 1)
283
284 #endif
This page took 0.039903 seconds and 4 git commands to generate.