sdhc.c revision 1.1.6.2 1 1.1.6.2 jym /* $NetBSD: sdhc.c,v 1.1.6.2 2009/05/13 17:21:29 jym Exp $ */
2 1.1.6.2 jym /* $OpenBSD: sdhc.c,v 1.25 2009/01/13 19:44:20 grange Exp $ */
3 1.1.6.2 jym
4 1.1.6.2 jym /*
5 1.1.6.2 jym * Copyright (c) 2006 Uwe Stuehler <uwe (at) openbsd.org>
6 1.1.6.2 jym *
7 1.1.6.2 jym * Permission to use, copy, modify, and distribute this software for any
8 1.1.6.2 jym * purpose with or without fee is hereby granted, provided that the above
9 1.1.6.2 jym * copyright notice and this permission notice appear in all copies.
10 1.1.6.2 jym *
11 1.1.6.2 jym * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 1.1.6.2 jym * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 1.1.6.2 jym * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 1.1.6.2 jym * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 1.1.6.2 jym * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 1.1.6.2 jym * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 1.1.6.2 jym * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 1.1.6.2 jym */
19 1.1.6.2 jym
20 1.1.6.2 jym /*
21 1.1.6.2 jym * SD Host Controller driver based on the SD Host Controller Standard
22 1.1.6.2 jym * Simplified Specification Version 1.00 (www.sdcard.com).
23 1.1.6.2 jym */
24 1.1.6.2 jym
25 1.1.6.2 jym #include <sys/cdefs.h>
26 1.1.6.2 jym __KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.1.6.2 2009/05/13 17:21:29 jym Exp $");
27 1.1.6.2 jym
28 1.1.6.2 jym #include <sys/param.h>
29 1.1.6.2 jym #include <sys/device.h>
30 1.1.6.2 jym #include <sys/kernel.h>
31 1.1.6.2 jym #include <sys/kthread.h>
32 1.1.6.2 jym #include <sys/malloc.h>
33 1.1.6.2 jym #include <sys/systm.h>
34 1.1.6.2 jym #include <sys/mutex.h>
35 1.1.6.2 jym #include <sys/condvar.h>
36 1.1.6.2 jym
37 1.1.6.2 jym #include <dev/sdmmc/sdhcreg.h>
38 1.1.6.2 jym #include <dev/sdmmc/sdhcvar.h>
39 1.1.6.2 jym #include <dev/sdmmc/sdmmcchip.h>
40 1.1.6.2 jym #include <dev/sdmmc/sdmmcreg.h>
41 1.1.6.2 jym #include <dev/sdmmc/sdmmcvar.h>
42 1.1.6.2 jym
43 1.1.6.2 jym #ifdef SDHC_DEBUG
44 1.1.6.2 jym int sdhcdebug = 1;
45 1.1.6.2 jym #define DPRINTF(n,s) do { if ((n) <= sdhcdebug) printf s; } while (0)
46 1.1.6.2 jym void sdhc_dump_regs(struct sdhc_host *);
47 1.1.6.2 jym #else
48 1.1.6.2 jym #define DPRINTF(n,s) do {} while (0)
49 1.1.6.2 jym #endif
50 1.1.6.2 jym
51 1.1.6.2 jym #define SDHC_COMMAND_TIMEOUT hz
52 1.1.6.2 jym #define SDHC_BUFFER_TIMEOUT hz
53 1.1.6.2 jym #define SDHC_TRANSFER_TIMEOUT hz
54 1.1.6.2 jym #define SDHC_DMA_TIMEOUT hz
55 1.1.6.2 jym
56 1.1.6.2 jym struct sdhc_host {
57 1.1.6.2 jym struct sdhc_softc *sc; /* host controller device */
58 1.1.6.2 jym
59 1.1.6.2 jym bus_space_tag_t iot; /* host register set tag */
60 1.1.6.2 jym bus_space_handle_t ioh; /* host register set handle */
61 1.1.6.2 jym bus_dma_tag_t dmat; /* host DMA tag */
62 1.1.6.2 jym
63 1.1.6.2 jym device_t sdmmc; /* generic SD/MMC device */
64 1.1.6.2 jym
65 1.1.6.2 jym struct kmutex host_mtx;
66 1.1.6.2 jym
67 1.1.6.2 jym u_int clkbase; /* base clock frequency in KHz */
68 1.1.6.2 jym int maxblklen; /* maximum block length */
69 1.1.6.2 jym uint32_t ocr; /* OCR value from capabilities */
70 1.1.6.2 jym
71 1.1.6.2 jym uint8_t regs[14]; /* host controller state */
72 1.1.6.2 jym
73 1.1.6.2 jym uint16_t intr_status; /* soft interrupt status */
74 1.1.6.2 jym uint16_t intr_error_status; /* soft error status */
75 1.1.6.2 jym struct kmutex intr_mtx;
76 1.1.6.2 jym struct kcondvar intr_cv;
77 1.1.6.2 jym
78 1.1.6.2 jym uint32_t flags; /* flags for this host */
79 1.1.6.2 jym #define SHF_USE_DMA 0x0001
80 1.1.6.2 jym #define SHF_USE_4BIT_MODE 0x0002
81 1.1.6.2 jym };
82 1.1.6.2 jym
83 1.1.6.2 jym #define HDEVNAME(hp) (device_xname((hp)->sc->sc_dev))
84 1.1.6.2 jym
85 1.1.6.2 jym #define HREAD1(hp, reg) \
86 1.1.6.2 jym (bus_space_read_1((hp)->iot, (hp)->ioh, (reg)))
87 1.1.6.2 jym #define HREAD2(hp, reg) \
88 1.1.6.2 jym (bus_space_read_2((hp)->iot, (hp)->ioh, (reg)))
89 1.1.6.2 jym #define HREAD4(hp, reg) \
90 1.1.6.2 jym (bus_space_read_4((hp)->iot, (hp)->ioh, (reg)))
91 1.1.6.2 jym #define HWRITE1(hp, reg, val) \
92 1.1.6.2 jym bus_space_write_1((hp)->iot, (hp)->ioh, (reg), (val))
93 1.1.6.2 jym #define HWRITE2(hp, reg, val) \
94 1.1.6.2 jym bus_space_write_2((hp)->iot, (hp)->ioh, (reg), (val))
95 1.1.6.2 jym #define HWRITE4(hp, reg, val) \
96 1.1.6.2 jym bus_space_write_4((hp)->iot, (hp)->ioh, (reg), (val))
97 1.1.6.2 jym #define HCLR1(hp, reg, bits) \
98 1.1.6.2 jym HWRITE1((hp), (reg), HREAD1((hp), (reg)) & ~(bits))
99 1.1.6.2 jym #define HCLR2(hp, reg, bits) \
100 1.1.6.2 jym HWRITE2((hp), (reg), HREAD2((hp), (reg)) & ~(bits))
101 1.1.6.2 jym #define HSET1(hp, reg, bits) \
102 1.1.6.2 jym HWRITE1((hp), (reg), HREAD1((hp), (reg)) | (bits))
103 1.1.6.2 jym #define HSET2(hp, reg, bits) \
104 1.1.6.2 jym HWRITE2((hp), (reg), HREAD2((hp), (reg)) | (bits))
105 1.1.6.2 jym
106 1.1.6.2 jym static int sdhc_host_reset(sdmmc_chipset_handle_t);
107 1.1.6.2 jym static int sdhc_host_reset1(sdmmc_chipset_handle_t);
108 1.1.6.2 jym static uint32_t sdhc_host_ocr(sdmmc_chipset_handle_t);
109 1.1.6.2 jym static int sdhc_host_maxblklen(sdmmc_chipset_handle_t);
110 1.1.6.2 jym static int sdhc_card_detect(sdmmc_chipset_handle_t);
111 1.1.6.2 jym static int sdhc_write_protect(sdmmc_chipset_handle_t);
112 1.1.6.2 jym static int sdhc_bus_power(sdmmc_chipset_handle_t, uint32_t);
113 1.1.6.2 jym static int sdhc_bus_clock(sdmmc_chipset_handle_t, int);
114 1.1.6.2 jym static int sdhc_bus_width(sdmmc_chipset_handle_t, int);
115 1.1.6.2 jym static void sdhc_card_enable_intr(sdmmc_chipset_handle_t, int);
116 1.1.6.2 jym static void sdhc_card_intr_ack(sdmmc_chipset_handle_t);
117 1.1.6.2 jym static void sdhc_exec_command(sdmmc_chipset_handle_t,
118 1.1.6.2 jym struct sdmmc_command *);
119 1.1.6.2 jym static int sdhc_start_command(struct sdhc_host *, struct sdmmc_command *);
120 1.1.6.2 jym static int sdhc_wait_state(struct sdhc_host *, uint32_t, uint32_t);
121 1.1.6.2 jym static int sdhc_soft_reset(struct sdhc_host *, int);
122 1.1.6.2 jym static int sdhc_wait_intr(struct sdhc_host *, int, int);
123 1.1.6.2 jym static void sdhc_transfer_data(struct sdhc_host *, struct sdmmc_command *);
124 1.1.6.2 jym static int sdhc_transfer_data_pio(struct sdhc_host *, struct sdmmc_command *);
125 1.1.6.2 jym static void sdhc_read_data_pio(struct sdhc_host *, uint8_t *, int);
126 1.1.6.2 jym static void sdhc_write_data_pio(struct sdhc_host *, uint8_t *, int);
127 1.1.6.2 jym
128 1.1.6.2 jym static struct sdmmc_chip_functions sdhc_functions = {
129 1.1.6.2 jym /* host controller reset */
130 1.1.6.2 jym sdhc_host_reset,
131 1.1.6.2 jym
132 1.1.6.2 jym /* host controller capabilities */
133 1.1.6.2 jym sdhc_host_ocr,
134 1.1.6.2 jym sdhc_host_maxblklen,
135 1.1.6.2 jym
136 1.1.6.2 jym /* card detection */
137 1.1.6.2 jym sdhc_card_detect,
138 1.1.6.2 jym
139 1.1.6.2 jym /* write protect */
140 1.1.6.2 jym sdhc_write_protect,
141 1.1.6.2 jym
142 1.1.6.2 jym /* bus power, clock frequency and width */
143 1.1.6.2 jym sdhc_bus_power,
144 1.1.6.2 jym sdhc_bus_clock,
145 1.1.6.2 jym sdhc_bus_width,
146 1.1.6.2 jym
147 1.1.6.2 jym /* command execution */
148 1.1.6.2 jym sdhc_exec_command,
149 1.1.6.2 jym
150 1.1.6.2 jym /* card interrupt */
151 1.1.6.2 jym sdhc_card_enable_intr,
152 1.1.6.2 jym sdhc_card_intr_ack
153 1.1.6.2 jym };
154 1.1.6.2 jym
155 1.1.6.2 jym /*
156 1.1.6.2 jym * Called by attachment driver. For each SD card slot there is one SD
157 1.1.6.2 jym * host controller standard register set. (1.3)
158 1.1.6.2 jym */
159 1.1.6.2 jym int
160 1.1.6.2 jym sdhc_host_found(struct sdhc_softc *sc, bus_space_tag_t iot,
161 1.1.6.2 jym bus_space_handle_t ioh, bus_size_t iosize)
162 1.1.6.2 jym {
163 1.1.6.2 jym struct sdmmcbus_attach_args saa;
164 1.1.6.2 jym struct sdhc_host *hp;
165 1.1.6.2 jym uint32_t caps;
166 1.1.6.2 jym #ifdef SDHC_DEBUG
167 1.1.6.2 jym uint16_t sdhcver;
168 1.1.6.2 jym
169 1.1.6.2 jym sdhcver = bus_space_read_2(iot, ioh, SDHC_HOST_CTL_VERSION);
170 1.1.6.2 jym aprint_normal_dev(sc->sc_dev, "SD Host Specification/Vendor Version ");
171 1.1.6.2 jym switch (SDHC_SPEC_VERSION(sdhcver)) {
172 1.1.6.2 jym case 0x00:
173 1.1.6.2 jym aprint_normal("1.0/%u\n", SDHC_VENDOR_VERSION(sdhcver));
174 1.1.6.2 jym break;
175 1.1.6.2 jym
176 1.1.6.2 jym default:
177 1.1.6.2 jym aprint_normal(">1.0/%u\n", SDHC_VENDOR_VERSION(sdhcver));
178 1.1.6.2 jym break;
179 1.1.6.2 jym }
180 1.1.6.2 jym #endif
181 1.1.6.2 jym
182 1.1.6.2 jym /* Allocate one more host structure. */
183 1.1.6.2 jym hp = malloc(sizeof(struct sdhc_host), M_DEVBUF, M_WAITOK|M_ZERO);
184 1.1.6.2 jym if (hp == NULL) {
185 1.1.6.2 jym aprint_error_dev(sc->sc_dev,
186 1.1.6.2 jym "couldn't alloc memory (sdhc host)\n");
187 1.1.6.2 jym goto err1;
188 1.1.6.2 jym }
189 1.1.6.2 jym sc->sc_host[sc->sc_nhosts++] = hp;
190 1.1.6.2 jym
191 1.1.6.2 jym /* Fill in the new host structure. */
192 1.1.6.2 jym hp->sc = sc;
193 1.1.6.2 jym hp->iot = iot;
194 1.1.6.2 jym hp->ioh = ioh;
195 1.1.6.2 jym hp->dmat = sc->sc_dmat;
196 1.1.6.2 jym
197 1.1.6.2 jym mutex_init(&hp->host_mtx, MUTEX_DEFAULT, IPL_SDMMC);
198 1.1.6.2 jym mutex_init(&hp->intr_mtx, MUTEX_DEFAULT, IPL_SDMMC);
199 1.1.6.2 jym cv_init(&hp->intr_cv, "sdhcintr");
200 1.1.6.2 jym
201 1.1.6.2 jym /*
202 1.1.6.2 jym * eset the host controller and enable interrupts.
203 1.1.6.2 jym */
204 1.1.6.2 jym (void)sdhc_host_reset(hp);
205 1.1.6.2 jym
206 1.1.6.2 jym /* Determine host capabilities. */
207 1.1.6.2 jym mutex_enter(&hp->host_mtx);
208 1.1.6.2 jym caps = HREAD4(hp, SDHC_CAPABILITIES);
209 1.1.6.2 jym mutex_exit(&hp->host_mtx);
210 1.1.6.2 jym
211 1.1.6.2 jym #if notyet
212 1.1.6.2 jym /* Use DMA if the host system and the controller support it. */
213 1.1.6.2 jym if (ISSET(sc->sc_flags, SDHC_FLAG_FORCE_DMA)
214 1.1.6.2 jym || ((ISSET(sc->sc_flags, SDHC_FLAG_USE_DMA)
215 1.1.6.2 jym && ISSET(caps, SDHC_DMA_SUPPORT)))) {
216 1.1.6.2 jym SET(hp->flags, SHF_USE_DMA);
217 1.1.6.2 jym aprint_normal_dev(sc->sc_dev, "using DMA transfer\n");
218 1.1.6.2 jym }
219 1.1.6.2 jym #endif
220 1.1.6.2 jym
221 1.1.6.2 jym /*
222 1.1.6.2 jym * Determine the base clock frequency. (2.2.24)
223 1.1.6.2 jym */
224 1.1.6.2 jym if (SDHC_BASE_FREQ_KHZ(caps) != 0)
225 1.1.6.2 jym hp->clkbase = SDHC_BASE_FREQ_KHZ(caps);
226 1.1.6.2 jym if (hp->clkbase == 0) {
227 1.1.6.2 jym /* The attachment driver must tell us. */
228 1.1.6.2 jym aprint_error_dev(sc->sc_dev,"unknown base clock frequency\n");
229 1.1.6.2 jym goto err;
230 1.1.6.2 jym } else if (hp->clkbase < 10000 || hp->clkbase > 63000) {
231 1.1.6.2 jym /* SDHC 1.0 supports only 10-63 MHz. */
232 1.1.6.2 jym aprint_error_dev(sc->sc_dev,
233 1.1.6.2 jym "base clock frequency out of range: %u MHz\n",
234 1.1.6.2 jym hp->clkbase / 1000);
235 1.1.6.2 jym goto err;
236 1.1.6.2 jym }
237 1.1.6.2 jym DPRINTF(1,("%s: base clock frequency %u MHz\n",
238 1.1.6.2 jym device_xname(sc->sc_dev), hp->clkbase / 1000));
239 1.1.6.2 jym
240 1.1.6.2 jym /*
241 1.1.6.2 jym * XXX Set the data timeout counter value according to
242 1.1.6.2 jym * capabilities. (2.2.15)
243 1.1.6.2 jym */
244 1.1.6.2 jym HWRITE1(hp, SDHC_TIMEOUT_CTL, SDHC_TIMEOUT_MAX);
245 1.1.6.2 jym
246 1.1.6.2 jym /*
247 1.1.6.2 jym * Determine SD bus voltage levels supported by the controller.
248 1.1.6.2 jym */
249 1.1.6.2 jym if (ISSET(caps, SDHC_VOLTAGE_SUPP_1_8V))
250 1.1.6.2 jym SET(hp->ocr, MMC_OCR_1_7V_1_8V | MMC_OCR_1_8V_1_9V);
251 1.1.6.2 jym if (ISSET(caps, SDHC_VOLTAGE_SUPP_3_0V))
252 1.1.6.2 jym SET(hp->ocr, MMC_OCR_2_9V_3_0V | MMC_OCR_3_0V_3_1V);
253 1.1.6.2 jym if (ISSET(caps, SDHC_VOLTAGE_SUPP_3_3V))
254 1.1.6.2 jym SET(hp->ocr, MMC_OCR_3_2V_3_3V | MMC_OCR_3_3V_3_4V);
255 1.1.6.2 jym
256 1.1.6.2 jym /*
257 1.1.6.2 jym * Determine the maximum block length supported by the host
258 1.1.6.2 jym * controller. (2.2.24)
259 1.1.6.2 jym */
260 1.1.6.2 jym switch((caps >> SDHC_MAX_BLK_LEN_SHIFT) & SDHC_MAX_BLK_LEN_MASK) {
261 1.1.6.2 jym case SDHC_MAX_BLK_LEN_512:
262 1.1.6.2 jym hp->maxblklen = 512;
263 1.1.6.2 jym break;
264 1.1.6.2 jym
265 1.1.6.2 jym case SDHC_MAX_BLK_LEN_1024:
266 1.1.6.2 jym hp->maxblklen = 1024;
267 1.1.6.2 jym break;
268 1.1.6.2 jym
269 1.1.6.2 jym case SDHC_MAX_BLK_LEN_2048:
270 1.1.6.2 jym hp->maxblklen = 2048;
271 1.1.6.2 jym break;
272 1.1.6.2 jym
273 1.1.6.2 jym default:
274 1.1.6.2 jym aprint_error_dev(sc->sc_dev, "max block length unknown\n");
275 1.1.6.2 jym goto err;
276 1.1.6.2 jym }
277 1.1.6.2 jym DPRINTF(1, ("%s: max block length %u byte%s\n",
278 1.1.6.2 jym device_xname(sc->sc_dev), hp->maxblklen,
279 1.1.6.2 jym hp->maxblklen > 1 ? "s" : ""));
280 1.1.6.2 jym
281 1.1.6.2 jym /*
282 1.1.6.2 jym * Attach the generic SD/MMC bus driver. (The bus driver must
283 1.1.6.2 jym * not invoke any chipset functions before it is attached.)
284 1.1.6.2 jym */
285 1.1.6.2 jym memset(&saa, 0, sizeof(saa));
286 1.1.6.2 jym saa.saa_busname = "sdmmc";
287 1.1.6.2 jym saa.saa_sct = &sdhc_functions;
288 1.1.6.2 jym saa.saa_sch = hp;
289 1.1.6.2 jym saa.saa_dmat = hp->dmat;
290 1.1.6.2 jym saa.saa_clkmin = hp->clkbase / 256;
291 1.1.6.2 jym saa.saa_clkmax = hp->clkbase;
292 1.1.6.2 jym saa.saa_caps = SMC_CAPS_4BIT_MODE|SMC_CAPS_AUTO_STOP;
293 1.1.6.2 jym #if notyet
294 1.1.6.2 jym if (ISSET(hp->flags, SHF_USE_DMA))
295 1.1.6.2 jym saa.saa_caps |= SMC_CAPS_DMA;
296 1.1.6.2 jym #endif
297 1.1.6.2 jym
298 1.1.6.2 jym hp->sdmmc = config_found(sc->sc_dev, &saa, NULL);
299 1.1.6.2 jym
300 1.1.6.2 jym return 0;
301 1.1.6.2 jym
302 1.1.6.2 jym err:
303 1.1.6.2 jym cv_destroy(&hp->intr_cv);
304 1.1.6.2 jym mutex_destroy(&hp->intr_mtx);
305 1.1.6.2 jym mutex_destroy(&hp->host_mtx);
306 1.1.6.2 jym free(hp, M_DEVBUF);
307 1.1.6.2 jym sc->sc_host[--sc->sc_nhosts] = NULL;
308 1.1.6.2 jym err1:
309 1.1.6.2 jym return 1;
310 1.1.6.2 jym }
311 1.1.6.2 jym
312 1.1.6.2 jym bool
313 1.1.6.2 jym sdhc_suspend(device_t dev PMF_FN_ARGS)
314 1.1.6.2 jym {
315 1.1.6.2 jym struct sdhc_softc *sc = device_private(dev);
316 1.1.6.2 jym struct sdhc_host *hp;
317 1.1.6.2 jym int n, i;
318 1.1.6.2 jym
319 1.1.6.2 jym /* XXX poll for command completion or suspend command
320 1.1.6.2 jym * in progress */
321 1.1.6.2 jym
322 1.1.6.2 jym /* Save the host controller state. */
323 1.1.6.2 jym for (n = 0; n < sc->sc_nhosts; n++) {
324 1.1.6.2 jym hp = sc->sc_host[n];
325 1.1.6.2 jym for (i = 0; i < sizeof hp->regs; i++)
326 1.1.6.2 jym hp->regs[i] = HREAD1(hp, i);
327 1.1.6.2 jym }
328 1.1.6.2 jym return true;
329 1.1.6.2 jym }
330 1.1.6.2 jym
331 1.1.6.2 jym bool
332 1.1.6.2 jym sdhc_resume(device_t dev PMF_FN_ARGS)
333 1.1.6.2 jym {
334 1.1.6.2 jym struct sdhc_softc *sc = device_private(dev);
335 1.1.6.2 jym struct sdhc_host *hp;
336 1.1.6.2 jym int n, i;
337 1.1.6.2 jym
338 1.1.6.2 jym /* Restore the host controller state. */
339 1.1.6.2 jym for (n = 0; n < sc->sc_nhosts; n++) {
340 1.1.6.2 jym hp = sc->sc_host[n];
341 1.1.6.2 jym (void)sdhc_host_reset(hp);
342 1.1.6.2 jym for (i = 0; i < sizeof hp->regs; i++)
343 1.1.6.2 jym HWRITE1(hp, i, hp->regs[i]);
344 1.1.6.2 jym }
345 1.1.6.2 jym return true;
346 1.1.6.2 jym }
347 1.1.6.2 jym
348 1.1.6.2 jym bool
349 1.1.6.2 jym sdhc_shutdown(device_t dev, int flags)
350 1.1.6.2 jym {
351 1.1.6.2 jym struct sdhc_softc *sc = device_private(dev);
352 1.1.6.2 jym struct sdhc_host *hp;
353 1.1.6.2 jym int i;
354 1.1.6.2 jym
355 1.1.6.2 jym /* XXX chip locks up if we don't disable it before reboot. */
356 1.1.6.2 jym for (i = 0; i < sc->sc_nhosts; i++) {
357 1.1.6.2 jym hp = sc->sc_host[i];
358 1.1.6.2 jym (void)sdhc_host_reset(hp);
359 1.1.6.2 jym }
360 1.1.6.2 jym return true;
361 1.1.6.2 jym }
362 1.1.6.2 jym
363 1.1.6.2 jym /*
364 1.1.6.2 jym * Reset the host controller. Called during initialization, when
365 1.1.6.2 jym * cards are removed, upon resume, and during error recovery.
366 1.1.6.2 jym */
367 1.1.6.2 jym static int
368 1.1.6.2 jym sdhc_host_reset1(sdmmc_chipset_handle_t sch)
369 1.1.6.2 jym {
370 1.1.6.2 jym struct sdhc_host *hp = (struct sdhc_host *)sch;
371 1.1.6.2 jym uint16_t sdhcimask;
372 1.1.6.2 jym int error;
373 1.1.6.2 jym
374 1.1.6.2 jym /* Don't lock. */
375 1.1.6.2 jym
376 1.1.6.2 jym /* Disable all interrupts. */
377 1.1.6.2 jym HWRITE2(hp, SDHC_NINTR_SIGNAL_EN, 0);
378 1.1.6.2 jym
379 1.1.6.2 jym /*
380 1.1.6.2 jym * Reset the entire host controller and wait up to 100ms for
381 1.1.6.2 jym * the controller to clear the reset bit.
382 1.1.6.2 jym */
383 1.1.6.2 jym error = sdhc_soft_reset(hp, SDHC_RESET_ALL);
384 1.1.6.2 jym if (error)
385 1.1.6.2 jym goto out;
386 1.1.6.2 jym
387 1.1.6.2 jym /* Set data timeout counter value to max for now. */
388 1.1.6.2 jym HWRITE1(hp, SDHC_TIMEOUT_CTL, SDHC_TIMEOUT_MAX);
389 1.1.6.2 jym
390 1.1.6.2 jym /* Enable interrupts. */
391 1.1.6.2 jym sdhcimask = SDHC_CARD_REMOVAL | SDHC_CARD_INSERTION |
392 1.1.6.2 jym SDHC_BUFFER_READ_READY | SDHC_BUFFER_WRITE_READY |
393 1.1.6.2 jym SDHC_DMA_INTERRUPT | SDHC_BLOCK_GAP_EVENT |
394 1.1.6.2 jym SDHC_TRANSFER_COMPLETE | SDHC_COMMAND_COMPLETE;
395 1.1.6.2 jym HWRITE2(hp, SDHC_NINTR_STATUS_EN, sdhcimask);
396 1.1.6.2 jym HWRITE2(hp, SDHC_EINTR_STATUS_EN, SDHC_EINTR_STATUS_MASK);
397 1.1.6.2 jym HWRITE2(hp, SDHC_NINTR_SIGNAL_EN, sdhcimask);
398 1.1.6.2 jym HWRITE2(hp, SDHC_EINTR_SIGNAL_EN, SDHC_EINTR_SIGNAL_MASK);
399 1.1.6.2 jym
400 1.1.6.2 jym out:
401 1.1.6.2 jym return error;
402 1.1.6.2 jym }
403 1.1.6.2 jym
404 1.1.6.2 jym static int
405 1.1.6.2 jym sdhc_host_reset(sdmmc_chipset_handle_t sch)
406 1.1.6.2 jym {
407 1.1.6.2 jym struct sdhc_host *hp = (struct sdhc_host *)sch;
408 1.1.6.2 jym int error;
409 1.1.6.2 jym
410 1.1.6.2 jym mutex_enter(&hp->host_mtx);
411 1.1.6.2 jym error = sdhc_host_reset1(sch);
412 1.1.6.2 jym mutex_exit(&hp->host_mtx);
413 1.1.6.2 jym
414 1.1.6.2 jym return error;
415 1.1.6.2 jym }
416 1.1.6.2 jym
417 1.1.6.2 jym static uint32_t
418 1.1.6.2 jym sdhc_host_ocr(sdmmc_chipset_handle_t sch)
419 1.1.6.2 jym {
420 1.1.6.2 jym struct sdhc_host *hp = (struct sdhc_host *)sch;
421 1.1.6.2 jym
422 1.1.6.2 jym return hp->ocr;
423 1.1.6.2 jym }
424 1.1.6.2 jym
425 1.1.6.2 jym static int
426 1.1.6.2 jym sdhc_host_maxblklen(sdmmc_chipset_handle_t sch)
427 1.1.6.2 jym {
428 1.1.6.2 jym struct sdhc_host *hp = (struct sdhc_host *)sch;
429 1.1.6.2 jym
430 1.1.6.2 jym return hp->maxblklen;
431 1.1.6.2 jym }
432 1.1.6.2 jym
433 1.1.6.2 jym /*
434 1.1.6.2 jym * Return non-zero if the card is currently inserted.
435 1.1.6.2 jym */
436 1.1.6.2 jym static int
437 1.1.6.2 jym sdhc_card_detect(sdmmc_chipset_handle_t sch)
438 1.1.6.2 jym {
439 1.1.6.2 jym struct sdhc_host *hp = (struct sdhc_host *)sch;
440 1.1.6.2 jym int r;
441 1.1.6.2 jym
442 1.1.6.2 jym mutex_enter(&hp->host_mtx);
443 1.1.6.2 jym r = ISSET(HREAD4(hp, SDHC_PRESENT_STATE), SDHC_CARD_INSERTED);
444 1.1.6.2 jym mutex_exit(&hp->host_mtx);
445 1.1.6.2 jym
446 1.1.6.2 jym if (r)
447 1.1.6.2 jym return 1;
448 1.1.6.2 jym return 0;
449 1.1.6.2 jym }
450 1.1.6.2 jym
451 1.1.6.2 jym /*
452 1.1.6.2 jym * Return non-zero if the card is currently write-protected.
453 1.1.6.2 jym */
454 1.1.6.2 jym static int
455 1.1.6.2 jym sdhc_write_protect(sdmmc_chipset_handle_t sch)
456 1.1.6.2 jym {
457 1.1.6.2 jym struct sdhc_host *hp = (struct sdhc_host *)sch;
458 1.1.6.2 jym int r;
459 1.1.6.2 jym
460 1.1.6.2 jym mutex_enter(&hp->host_mtx);
461 1.1.6.2 jym r = ISSET(HREAD4(hp, SDHC_PRESENT_STATE), SDHC_WRITE_PROTECT_SWITCH);
462 1.1.6.2 jym mutex_exit(&hp->host_mtx);
463 1.1.6.2 jym
464 1.1.6.2 jym if (!r)
465 1.1.6.2 jym return 1;
466 1.1.6.2 jym return 0;
467 1.1.6.2 jym }
468 1.1.6.2 jym
469 1.1.6.2 jym /*
470 1.1.6.2 jym * Set or change SD bus voltage and enable or disable SD bus power.
471 1.1.6.2 jym * Return zero on success.
472 1.1.6.2 jym */
473 1.1.6.2 jym static int
474 1.1.6.2 jym sdhc_bus_power(sdmmc_chipset_handle_t sch, uint32_t ocr)
475 1.1.6.2 jym {
476 1.1.6.2 jym struct sdhc_host *hp = (struct sdhc_host *)sch;
477 1.1.6.2 jym uint8_t vdd;
478 1.1.6.2 jym int error = 0;
479 1.1.6.2 jym
480 1.1.6.2 jym mutex_enter(&hp->host_mtx);
481 1.1.6.2 jym
482 1.1.6.2 jym /*
483 1.1.6.2 jym * Disable bus power before voltage change.
484 1.1.6.2 jym */
485 1.1.6.2 jym if (!(hp->sc->sc_flags & SDHC_FLAG_NO_PWR0))
486 1.1.6.2 jym HWRITE1(hp, SDHC_POWER_CTL, 0);
487 1.1.6.2 jym
488 1.1.6.2 jym /* If power is disabled, reset the host and return now. */
489 1.1.6.2 jym if (ocr == 0) {
490 1.1.6.2 jym (void)sdhc_host_reset1(hp);
491 1.1.6.2 jym goto out;
492 1.1.6.2 jym }
493 1.1.6.2 jym
494 1.1.6.2 jym /*
495 1.1.6.2 jym * Select the lowest voltage according to capabilities.
496 1.1.6.2 jym */
497 1.1.6.2 jym ocr &= hp->ocr;
498 1.1.6.2 jym if (ISSET(ocr, MMC_OCR_1_7V_1_8V|MMC_OCR_1_8V_1_9V))
499 1.1.6.2 jym vdd = SDHC_VOLTAGE_1_8V;
500 1.1.6.2 jym else if (ISSET(ocr, MMC_OCR_2_9V_3_0V|MMC_OCR_3_0V_3_1V))
501 1.1.6.2 jym vdd = SDHC_VOLTAGE_3_0V;
502 1.1.6.2 jym else if (ISSET(ocr, MMC_OCR_3_2V_3_3V|MMC_OCR_3_3V_3_4V))
503 1.1.6.2 jym vdd = SDHC_VOLTAGE_3_3V;
504 1.1.6.2 jym else {
505 1.1.6.2 jym /* Unsupported voltage level requested. */
506 1.1.6.2 jym error = EINVAL;
507 1.1.6.2 jym goto out;
508 1.1.6.2 jym }
509 1.1.6.2 jym
510 1.1.6.2 jym /*
511 1.1.6.2 jym * Enable bus power. Wait at least 1 ms (or 74 clocks) plus
512 1.1.6.2 jym * voltage ramp until power rises.
513 1.1.6.2 jym */
514 1.1.6.2 jym HWRITE1(hp, SDHC_POWER_CTL,
515 1.1.6.2 jym (vdd << SDHC_VOLTAGE_SHIFT) | SDHC_BUS_POWER);
516 1.1.6.2 jym sdmmc_delay(10000);
517 1.1.6.2 jym
518 1.1.6.2 jym /*
519 1.1.6.2 jym * The host system may not power the bus due to battery low,
520 1.1.6.2 jym * etc. In that case, the host controller should clear the
521 1.1.6.2 jym * bus power bit.
522 1.1.6.2 jym */
523 1.1.6.2 jym if (!ISSET(HREAD1(hp, SDHC_POWER_CTL), SDHC_BUS_POWER)) {
524 1.1.6.2 jym error = ENXIO;
525 1.1.6.2 jym goto out;
526 1.1.6.2 jym }
527 1.1.6.2 jym
528 1.1.6.2 jym out:
529 1.1.6.2 jym mutex_exit(&hp->host_mtx);
530 1.1.6.2 jym
531 1.1.6.2 jym return error;
532 1.1.6.2 jym }
533 1.1.6.2 jym
534 1.1.6.2 jym /*
535 1.1.6.2 jym * Return the smallest possible base clock frequency divisor value
536 1.1.6.2 jym * for the CLOCK_CTL register to produce `freq' (KHz).
537 1.1.6.2 jym */
538 1.1.6.2 jym static int
539 1.1.6.2 jym sdhc_clock_divisor(struct sdhc_host *hp, u_int freq)
540 1.1.6.2 jym {
541 1.1.6.2 jym int div;
542 1.1.6.2 jym
543 1.1.6.2 jym for (div = 1; div <= 256; div *= 2)
544 1.1.6.2 jym if ((hp->clkbase / div) <= freq)
545 1.1.6.2 jym return (div / 2);
546 1.1.6.2 jym /* No divisor found. */
547 1.1.6.2 jym return -1;
548 1.1.6.2 jym }
549 1.1.6.2 jym
550 1.1.6.2 jym /*
551 1.1.6.2 jym * Set or change SDCLK frequency or disable the SD clock.
552 1.1.6.2 jym * Return zero on success.
553 1.1.6.2 jym */
554 1.1.6.2 jym static int
555 1.1.6.2 jym sdhc_bus_clock(sdmmc_chipset_handle_t sch, int freq)
556 1.1.6.2 jym {
557 1.1.6.2 jym struct sdhc_host *hp = (struct sdhc_host *)sch;
558 1.1.6.2 jym int div;
559 1.1.6.2 jym int timo;
560 1.1.6.2 jym int error = 0;
561 1.1.6.2 jym
562 1.1.6.2 jym mutex_enter(&hp->host_mtx);
563 1.1.6.2 jym
564 1.1.6.2 jym #ifdef DIAGNOSTIC
565 1.1.6.2 jym /* Must not stop the clock if commands are in progress. */
566 1.1.6.2 jym if (ISSET(HREAD4(hp, SDHC_PRESENT_STATE), SDHC_CMD_INHIBIT_MASK) &&
567 1.1.6.2 jym sdhc_card_detect(hp))
568 1.1.6.2 jym printf("%s: sdhc_sdclk_frequency_select: command in progress\n",
569 1.1.6.2 jym device_xname(hp->sc->sc_dev));
570 1.1.6.2 jym #endif
571 1.1.6.2 jym
572 1.1.6.2 jym /*
573 1.1.6.2 jym * Stop SD clock before changing the frequency.
574 1.1.6.2 jym */
575 1.1.6.2 jym HWRITE2(hp, SDHC_CLOCK_CTL, 0);
576 1.1.6.2 jym if (freq == SDMMC_SDCLK_OFF)
577 1.1.6.2 jym goto out;
578 1.1.6.2 jym
579 1.1.6.2 jym /*
580 1.1.6.2 jym * Set the minimum base clock frequency divisor.
581 1.1.6.2 jym */
582 1.1.6.2 jym if ((div = sdhc_clock_divisor(hp, freq)) < 0) {
583 1.1.6.2 jym /* Invalid base clock frequency or `freq' value. */
584 1.1.6.2 jym error = EINVAL;
585 1.1.6.2 jym goto out;
586 1.1.6.2 jym }
587 1.1.6.2 jym HWRITE2(hp, SDHC_CLOCK_CTL, div << SDHC_SDCLK_DIV_SHIFT);
588 1.1.6.2 jym
589 1.1.6.2 jym /*
590 1.1.6.2 jym * Start internal clock. Wait 10ms for stabilization.
591 1.1.6.2 jym */
592 1.1.6.2 jym HSET2(hp, SDHC_CLOCK_CTL, SDHC_INTCLK_ENABLE);
593 1.1.6.2 jym for (timo = 1000; timo > 0; timo--) {
594 1.1.6.2 jym if (ISSET(HREAD2(hp, SDHC_CLOCK_CTL), SDHC_INTCLK_STABLE))
595 1.1.6.2 jym break;
596 1.1.6.2 jym sdmmc_delay(10);
597 1.1.6.2 jym }
598 1.1.6.2 jym if (timo == 0) {
599 1.1.6.2 jym error = ETIMEDOUT;
600 1.1.6.2 jym goto out;
601 1.1.6.2 jym }
602 1.1.6.2 jym
603 1.1.6.2 jym /*
604 1.1.6.2 jym * Enable SD clock.
605 1.1.6.2 jym */
606 1.1.6.2 jym HSET2(hp, SDHC_CLOCK_CTL, SDHC_SDCLK_ENABLE);
607 1.1.6.2 jym
608 1.1.6.2 jym out:
609 1.1.6.2 jym mutex_exit(&hp->host_mtx);
610 1.1.6.2 jym
611 1.1.6.2 jym return error;
612 1.1.6.2 jym }
613 1.1.6.2 jym
614 1.1.6.2 jym static int
615 1.1.6.2 jym sdhc_bus_width(sdmmc_chipset_handle_t sch, int width)
616 1.1.6.2 jym {
617 1.1.6.2 jym struct sdhc_host *hp = (struct sdhc_host *)sch;
618 1.1.6.2 jym int reg;
619 1.1.6.2 jym
620 1.1.6.2 jym switch (width) {
621 1.1.6.2 jym case 1:
622 1.1.6.2 jym case 4:
623 1.1.6.2 jym break;
624 1.1.6.2 jym
625 1.1.6.2 jym default:
626 1.1.6.2 jym DPRINTF(0,("%s: unsupported bus width (%d)\n",
627 1.1.6.2 jym HDEVNAME(hp), width));
628 1.1.6.2 jym return 1;
629 1.1.6.2 jym }
630 1.1.6.2 jym
631 1.1.6.2 jym mutex_enter(&hp->host_mtx);
632 1.1.6.2 jym reg = HREAD1(hp, SDHC_POWER_CTL);
633 1.1.6.2 jym reg &= ~SDHC_4BIT_MODE;
634 1.1.6.2 jym if (width == 4)
635 1.1.6.2 jym reg |= SDHC_4BIT_MODE;
636 1.1.6.2 jym HWRITE1(hp, SDHC_POWER_CTL, reg);
637 1.1.6.2 jym mutex_exit(&hp->host_mtx);
638 1.1.6.2 jym
639 1.1.6.2 jym return 0;
640 1.1.6.2 jym }
641 1.1.6.2 jym
642 1.1.6.2 jym static void
643 1.1.6.2 jym sdhc_card_enable_intr(sdmmc_chipset_handle_t sch, int enable)
644 1.1.6.2 jym {
645 1.1.6.2 jym struct sdhc_host *hp = (struct sdhc_host *)sch;
646 1.1.6.2 jym
647 1.1.6.2 jym mutex_enter(&hp->host_mtx);
648 1.1.6.2 jym if (enable) {
649 1.1.6.2 jym HSET2(hp, SDHC_NINTR_STATUS_EN, SDHC_CARD_INTERRUPT);
650 1.1.6.2 jym HSET2(hp, SDHC_NINTR_SIGNAL_EN, SDHC_CARD_INTERRUPT);
651 1.1.6.2 jym } else {
652 1.1.6.2 jym HCLR2(hp, SDHC_NINTR_SIGNAL_EN, SDHC_CARD_INTERRUPT);
653 1.1.6.2 jym HCLR2(hp, SDHC_NINTR_STATUS_EN, SDHC_CARD_INTERRUPT);
654 1.1.6.2 jym }
655 1.1.6.2 jym mutex_exit(&hp->host_mtx);
656 1.1.6.2 jym }
657 1.1.6.2 jym
658 1.1.6.2 jym static void
659 1.1.6.2 jym sdhc_card_intr_ack(sdmmc_chipset_handle_t sch)
660 1.1.6.2 jym {
661 1.1.6.2 jym struct sdhc_host *hp = (struct sdhc_host *)sch;
662 1.1.6.2 jym
663 1.1.6.2 jym mutex_enter(&hp->host_mtx);
664 1.1.6.2 jym HSET2(hp, SDHC_NINTR_STATUS_EN, SDHC_CARD_INTERRUPT);
665 1.1.6.2 jym mutex_exit(&hp->host_mtx);
666 1.1.6.2 jym }
667 1.1.6.2 jym
668 1.1.6.2 jym static int
669 1.1.6.2 jym sdhc_wait_state(struct sdhc_host *hp, uint32_t mask, uint32_t value)
670 1.1.6.2 jym {
671 1.1.6.2 jym uint32_t state;
672 1.1.6.2 jym int timeout;
673 1.1.6.2 jym
674 1.1.6.2 jym for (timeout = 10; timeout > 0; timeout--) {
675 1.1.6.2 jym if (((state = HREAD4(hp, SDHC_PRESENT_STATE)) & mask) == value)
676 1.1.6.2 jym return 0;
677 1.1.6.2 jym sdmmc_delay(10000);
678 1.1.6.2 jym }
679 1.1.6.2 jym DPRINTF(0,("%s: timeout waiting for %x (state=%x)\n", HDEVNAME(hp),
680 1.1.6.2 jym value, state));
681 1.1.6.2 jym return ETIMEDOUT;
682 1.1.6.2 jym }
683 1.1.6.2 jym
684 1.1.6.2 jym static void
685 1.1.6.2 jym sdhc_exec_command(sdmmc_chipset_handle_t sch, struct sdmmc_command *cmd)
686 1.1.6.2 jym {
687 1.1.6.2 jym struct sdhc_host *hp = (struct sdhc_host *)sch;
688 1.1.6.2 jym int error;
689 1.1.6.2 jym
690 1.1.6.2 jym /*
691 1.1.6.2 jym * Start the MMC command, or mark `cmd' as failed and return.
692 1.1.6.2 jym */
693 1.1.6.2 jym error = sdhc_start_command(hp, cmd);
694 1.1.6.2 jym if (error) {
695 1.1.6.2 jym cmd->c_error = error;
696 1.1.6.2 jym goto out;
697 1.1.6.2 jym }
698 1.1.6.2 jym
699 1.1.6.2 jym /*
700 1.1.6.2 jym * Wait until the command phase is done, or until the command
701 1.1.6.2 jym * is marked done for any other reason.
702 1.1.6.2 jym */
703 1.1.6.2 jym if (!sdhc_wait_intr(hp, SDHC_COMMAND_COMPLETE, SDHC_COMMAND_TIMEOUT)) {
704 1.1.6.2 jym cmd->c_error = ETIMEDOUT;
705 1.1.6.2 jym goto out;
706 1.1.6.2 jym }
707 1.1.6.2 jym
708 1.1.6.2 jym /*
709 1.1.6.2 jym * The host controller removes bits [0:7] from the response
710 1.1.6.2 jym * data (CRC) and we pass the data up unchanged to the bus
711 1.1.6.2 jym * driver (without padding).
712 1.1.6.2 jym */
713 1.1.6.2 jym mutex_enter(&hp->host_mtx);
714 1.1.6.2 jym if (cmd->c_error == 0 && ISSET(cmd->c_flags, SCF_RSP_PRESENT)) {
715 1.1.6.2 jym if (ISSET(cmd->c_flags, SCF_RSP_136)) {
716 1.1.6.2 jym uint8_t *p = (uint8_t *)cmd->c_resp;
717 1.1.6.2 jym int i;
718 1.1.6.2 jym
719 1.1.6.2 jym for (i = 0; i < 15; i++)
720 1.1.6.2 jym *p++ = HREAD1(hp, SDHC_RESPONSE + i);
721 1.1.6.2 jym } else {
722 1.1.6.2 jym cmd->c_resp[0] = HREAD4(hp, SDHC_RESPONSE);
723 1.1.6.2 jym }
724 1.1.6.2 jym }
725 1.1.6.2 jym mutex_exit(&hp->host_mtx);
726 1.1.6.2 jym DPRINTF(1,("%s: resp = %08x\n", HDEVNAME(hp), cmd->c_resp[0]));
727 1.1.6.2 jym
728 1.1.6.2 jym /*
729 1.1.6.2 jym * If the command has data to transfer in any direction,
730 1.1.6.2 jym * execute the transfer now.
731 1.1.6.2 jym */
732 1.1.6.2 jym if (cmd->c_error == 0 && cmd->c_data != NULL)
733 1.1.6.2 jym sdhc_transfer_data(hp, cmd);
734 1.1.6.2 jym
735 1.1.6.2 jym out:
736 1.1.6.2 jym mutex_enter(&hp->host_mtx);
737 1.1.6.2 jym /* Turn off the LED. */
738 1.1.6.2 jym HCLR1(hp, SDHC_HOST_CTL, SDHC_LED_ON);
739 1.1.6.2 jym mutex_exit(&hp->host_mtx);
740 1.1.6.2 jym SET(cmd->c_flags, SCF_ITSDONE);
741 1.1.6.2 jym
742 1.1.6.2 jym DPRINTF(1,("%s: cmd %d %s (flags=%08x error=%d)\n", HDEVNAME(hp),
743 1.1.6.2 jym cmd->c_opcode, (cmd->c_error == 0) ? "done" : "abort",
744 1.1.6.2 jym cmd->c_flags, cmd->c_error));
745 1.1.6.2 jym }
746 1.1.6.2 jym
747 1.1.6.2 jym static int
748 1.1.6.2 jym sdhc_start_command(struct sdhc_host *hp, struct sdmmc_command *cmd)
749 1.1.6.2 jym {
750 1.1.6.2 jym uint16_t blksize = 0;
751 1.1.6.2 jym uint16_t blkcount = 0;
752 1.1.6.2 jym uint16_t mode;
753 1.1.6.2 jym uint16_t command;
754 1.1.6.2 jym int error;
755 1.1.6.2 jym
756 1.1.6.2 jym DPRINTF(1,("%s: start cmd %d arg=%08x data=%p dlen=%d flags=%08x "
757 1.1.6.2 jym "proc=%p \"%s\"\n", HDEVNAME(hp), cmd->c_opcode, cmd->c_arg,
758 1.1.6.2 jym cmd->c_data, cmd->c_datalen, cmd->c_flags, curproc,
759 1.1.6.2 jym curproc ? curproc->p_comm : ""));
760 1.1.6.2 jym
761 1.1.6.2 jym /*
762 1.1.6.2 jym * The maximum block length for commands should be the minimum
763 1.1.6.2 jym * of the host buffer size and the card buffer size. (1.7.2)
764 1.1.6.2 jym */
765 1.1.6.2 jym
766 1.1.6.2 jym /* Fragment the data into proper blocks. */
767 1.1.6.2 jym if (cmd->c_datalen > 0) {
768 1.1.6.2 jym blksize = MIN(cmd->c_datalen, cmd->c_blklen);
769 1.1.6.2 jym blkcount = cmd->c_datalen / blksize;
770 1.1.6.2 jym if (cmd->c_datalen % blksize > 0) {
771 1.1.6.2 jym /* XXX: Split this command. (1.7.4) */
772 1.1.6.2 jym aprint_error_dev(hp->sc->sc_dev,
773 1.1.6.2 jym "data not a multiple of %u bytes\n", blksize);
774 1.1.6.2 jym return EINVAL;
775 1.1.6.2 jym }
776 1.1.6.2 jym }
777 1.1.6.2 jym
778 1.1.6.2 jym /* Check limit imposed by 9-bit block count. (1.7.2) */
779 1.1.6.2 jym if (blkcount > SDHC_BLOCK_COUNT_MAX) {
780 1.1.6.2 jym aprint_error_dev(hp->sc->sc_dev, "too much data\n");
781 1.1.6.2 jym return EINVAL;
782 1.1.6.2 jym }
783 1.1.6.2 jym
784 1.1.6.2 jym /* Prepare transfer mode register value. (2.2.5) */
785 1.1.6.2 jym mode = 0;
786 1.1.6.2 jym if (ISSET(cmd->c_flags, SCF_CMD_READ))
787 1.1.6.2 jym mode |= SDHC_READ_MODE;
788 1.1.6.2 jym if (blkcount > 0) {
789 1.1.6.2 jym mode |= SDHC_BLOCK_COUNT_ENABLE;
790 1.1.6.2 jym if (blkcount > 1) {
791 1.1.6.2 jym mode |= SDHC_MULTI_BLOCK_MODE;
792 1.1.6.2 jym /* XXX only for memory commands? */
793 1.1.6.2 jym mode |= SDHC_AUTO_CMD12_ENABLE;
794 1.1.6.2 jym }
795 1.1.6.2 jym }
796 1.1.6.2 jym #if notyet
797 1.1.6.2 jym if (cmd->c_dmap != NULL && cmd->c_datalen > 0)
798 1.1.6.2 jym mode |= SDHC_DMA_ENABLE;
799 1.1.6.2 jym #endif
800 1.1.6.2 jym
801 1.1.6.2 jym /*
802 1.1.6.2 jym * Prepare command register value. (2.2.6)
803 1.1.6.2 jym */
804 1.1.6.2 jym command =
805 1.1.6.2 jym (cmd->c_opcode & SDHC_COMMAND_INDEX_MASK) << SDHC_COMMAND_INDEX_SHIFT;
806 1.1.6.2 jym
807 1.1.6.2 jym if (ISSET(cmd->c_flags, SCF_RSP_CRC))
808 1.1.6.2 jym command |= SDHC_CRC_CHECK_ENABLE;
809 1.1.6.2 jym if (ISSET(cmd->c_flags, SCF_RSP_IDX))
810 1.1.6.2 jym command |= SDHC_INDEX_CHECK_ENABLE;
811 1.1.6.2 jym if (cmd->c_data != NULL)
812 1.1.6.2 jym command |= SDHC_DATA_PRESENT_SELECT;
813 1.1.6.2 jym
814 1.1.6.2 jym if (!ISSET(cmd->c_flags, SCF_RSP_PRESENT))
815 1.1.6.2 jym command |= SDHC_NO_RESPONSE;
816 1.1.6.2 jym else if (ISSET(cmd->c_flags, SCF_RSP_136))
817 1.1.6.2 jym command |= SDHC_RESP_LEN_136;
818 1.1.6.2 jym else if (ISSET(cmd->c_flags, SCF_RSP_BSY))
819 1.1.6.2 jym command |= SDHC_RESP_LEN_48_CHK_BUSY;
820 1.1.6.2 jym else
821 1.1.6.2 jym command |= SDHC_RESP_LEN_48;
822 1.1.6.2 jym
823 1.1.6.2 jym /* Wait until command and data inhibit bits are clear. (1.5) */
824 1.1.6.2 jym error = sdhc_wait_state(hp, SDHC_CMD_INHIBIT_MASK, 0);
825 1.1.6.2 jym if (error)
826 1.1.6.2 jym return error;
827 1.1.6.2 jym
828 1.1.6.2 jym DPRINTF(1,("%s: writing cmd: blksize=%d blkcnt=%d mode=%04x cmd=%04x\n",
829 1.1.6.2 jym HDEVNAME(hp), blksize, blkcount, mode, command));
830 1.1.6.2 jym
831 1.1.6.2 jym mutex_enter(&hp->host_mtx);
832 1.1.6.2 jym
833 1.1.6.2 jym /* Alert the user not to remove the card. */
834 1.1.6.2 jym HSET1(hp, SDHC_HOST_CTL, SDHC_LED_ON);
835 1.1.6.2 jym
836 1.1.6.2 jym /*
837 1.1.6.2 jym * Start a CPU data transfer. Writing to the high order byte
838 1.1.6.2 jym * of the SDHC_COMMAND register triggers the SD command. (1.5)
839 1.1.6.2 jym */
840 1.1.6.2 jym HWRITE2(hp, SDHC_TRANSFER_MODE, mode);
841 1.1.6.2 jym HWRITE2(hp, SDHC_BLOCK_SIZE, blksize);
842 1.1.6.2 jym if (blkcount > 1)
843 1.1.6.2 jym HWRITE2(hp, SDHC_BLOCK_COUNT, blkcount);
844 1.1.6.2 jym HWRITE4(hp, SDHC_ARGUMENT, cmd->c_arg);
845 1.1.6.2 jym HWRITE2(hp, SDHC_COMMAND, command);
846 1.1.6.2 jym
847 1.1.6.2 jym mutex_exit(&hp->host_mtx);
848 1.1.6.2 jym
849 1.1.6.2 jym return 0;
850 1.1.6.2 jym }
851 1.1.6.2 jym
852 1.1.6.2 jym static void
853 1.1.6.2 jym sdhc_transfer_data(struct sdhc_host *hp, struct sdmmc_command *cmd)
854 1.1.6.2 jym {
855 1.1.6.2 jym int error;
856 1.1.6.2 jym
857 1.1.6.2 jym DPRINTF(1,("%s: data transfer: resp=%08x datalen=%u\n", HDEVNAME(hp),
858 1.1.6.2 jym MMC_R1(cmd->c_resp), cmd->c_datalen));
859 1.1.6.2 jym
860 1.1.6.2 jym #ifdef SDHC_DEBUG
861 1.1.6.2 jym /* XXX I forgot why I wanted to know when this happens :-( */
862 1.1.6.2 jym if ((cmd->c_opcode == 52 || cmd->c_opcode == 53) &&
863 1.1.6.2 jym ISSET(MMC_R1(cmd->c_resp), 0xcb00)) {
864 1.1.6.2 jym aprint_error_dev(hp->sc->sc_dev,
865 1.1.6.2 jym "CMD52/53 error response flags %#x\n",
866 1.1.6.2 jym MMC_R1(cmd->c_resp) & 0xff00);
867 1.1.6.2 jym }
868 1.1.6.2 jym #endif
869 1.1.6.2 jym
870 1.1.6.2 jym error = sdhc_transfer_data_pio(hp, cmd);
871 1.1.6.2 jym if (error)
872 1.1.6.2 jym cmd->c_error = error;
873 1.1.6.2 jym SET(cmd->c_flags, SCF_ITSDONE);
874 1.1.6.2 jym
875 1.1.6.2 jym DPRINTF(1,("%s: data transfer done (error=%d)\n",
876 1.1.6.2 jym HDEVNAME(hp), cmd->c_error));
877 1.1.6.2 jym }
878 1.1.6.2 jym
879 1.1.6.2 jym static int
880 1.1.6.2 jym sdhc_transfer_data_pio(struct sdhc_host *hp, struct sdmmc_command *cmd)
881 1.1.6.2 jym {
882 1.1.6.2 jym uint8_t *data = cmd->c_data;
883 1.1.6.2 jym int len, datalen;
884 1.1.6.2 jym int mask;
885 1.1.6.2 jym int error = 0;
886 1.1.6.2 jym
887 1.1.6.2 jym mask = ISSET(cmd->c_flags, SCF_CMD_READ) ?
888 1.1.6.2 jym SDHC_BUFFER_READ_ENABLE : SDHC_BUFFER_WRITE_ENABLE;
889 1.1.6.2 jym datalen = cmd->c_datalen;
890 1.1.6.2 jym
891 1.1.6.2 jym while (datalen > 0) {
892 1.1.6.2 jym if (!sdhc_wait_intr(hp,
893 1.1.6.2 jym SDHC_BUFFER_READ_READY|SDHC_BUFFER_WRITE_READY,
894 1.1.6.2 jym SDHC_BUFFER_TIMEOUT)) {
895 1.1.6.2 jym error = ETIMEDOUT;
896 1.1.6.2 jym break;
897 1.1.6.2 jym }
898 1.1.6.2 jym
899 1.1.6.2 jym error = sdhc_wait_state(hp, mask, mask);
900 1.1.6.2 jym if (error)
901 1.1.6.2 jym break;
902 1.1.6.2 jym
903 1.1.6.2 jym len = MIN(datalen, cmd->c_blklen);
904 1.1.6.2 jym if (ISSET(cmd->c_flags, SCF_CMD_READ))
905 1.1.6.2 jym sdhc_read_data_pio(hp, data, len);
906 1.1.6.2 jym else
907 1.1.6.2 jym sdhc_write_data_pio(hp, data, len);
908 1.1.6.2 jym
909 1.1.6.2 jym data += len;
910 1.1.6.2 jym datalen -= len;
911 1.1.6.2 jym }
912 1.1.6.2 jym
913 1.1.6.2 jym if (error == 0 && !sdhc_wait_intr(hp, SDHC_TRANSFER_COMPLETE,
914 1.1.6.2 jym SDHC_TRANSFER_TIMEOUT))
915 1.1.6.2 jym error = ETIMEDOUT;
916 1.1.6.2 jym
917 1.1.6.2 jym return error;
918 1.1.6.2 jym }
919 1.1.6.2 jym
920 1.1.6.2 jym static void
921 1.1.6.2 jym sdhc_read_data_pio(struct sdhc_host *hp, uint8_t *data, int datalen)
922 1.1.6.2 jym {
923 1.1.6.2 jym
924 1.1.6.2 jym if (((__uintptr_t)data & 3) == 0) {
925 1.1.6.2 jym while (datalen > 3) {
926 1.1.6.2 jym *(uint32_t *)data = HREAD4(hp, SDHC_DATA);
927 1.1.6.2 jym data += 4;
928 1.1.6.2 jym datalen -= 4;
929 1.1.6.2 jym }
930 1.1.6.2 jym if (datalen > 1) {
931 1.1.6.2 jym *(uint16_t *)data = HREAD2(hp, SDHC_DATA);
932 1.1.6.2 jym data += 2;
933 1.1.6.2 jym datalen -= 2;
934 1.1.6.2 jym }
935 1.1.6.2 jym if (datalen > 0) {
936 1.1.6.2 jym *data = HREAD1(hp, SDHC_DATA);
937 1.1.6.2 jym data += 1;
938 1.1.6.2 jym datalen -= 1;
939 1.1.6.2 jym }
940 1.1.6.2 jym } else if (((__uintptr_t)data & 1) == 0) {
941 1.1.6.2 jym while (datalen > 1) {
942 1.1.6.2 jym *(uint16_t *)data = HREAD2(hp, SDHC_DATA);
943 1.1.6.2 jym data += 2;
944 1.1.6.2 jym datalen -= 2;
945 1.1.6.2 jym }
946 1.1.6.2 jym if (datalen > 0) {
947 1.1.6.2 jym *data = HREAD1(hp, SDHC_DATA);
948 1.1.6.2 jym data += 1;
949 1.1.6.2 jym datalen -= 1;
950 1.1.6.2 jym }
951 1.1.6.2 jym } else {
952 1.1.6.2 jym while (datalen > 0) {
953 1.1.6.2 jym *data = HREAD1(hp, SDHC_DATA);
954 1.1.6.2 jym data += 1;
955 1.1.6.2 jym datalen -= 1;
956 1.1.6.2 jym }
957 1.1.6.2 jym }
958 1.1.6.2 jym }
959 1.1.6.2 jym
960 1.1.6.2 jym static void
961 1.1.6.2 jym sdhc_write_data_pio(struct sdhc_host *hp, uint8_t *data, int datalen)
962 1.1.6.2 jym {
963 1.1.6.2 jym
964 1.1.6.2 jym if (((__uintptr_t)data & 3) == 0) {
965 1.1.6.2 jym while (datalen > 3) {
966 1.1.6.2 jym HWRITE4(hp, SDHC_DATA, *(uint32_t *)data);
967 1.1.6.2 jym data += 4;
968 1.1.6.2 jym datalen -= 4;
969 1.1.6.2 jym }
970 1.1.6.2 jym if (datalen > 1) {
971 1.1.6.2 jym HWRITE2(hp, SDHC_DATA, *(uint16_t *)data);
972 1.1.6.2 jym data += 2;
973 1.1.6.2 jym datalen -= 2;
974 1.1.6.2 jym }
975 1.1.6.2 jym if (datalen > 0) {
976 1.1.6.2 jym HWRITE1(hp, SDHC_DATA, *data);
977 1.1.6.2 jym data += 1;
978 1.1.6.2 jym datalen -= 1;
979 1.1.6.2 jym }
980 1.1.6.2 jym } else if (((__uintptr_t)data & 1) == 0) {
981 1.1.6.2 jym while (datalen > 1) {
982 1.1.6.2 jym HWRITE2(hp, SDHC_DATA, *(uint16_t *)data);
983 1.1.6.2 jym data += 2;
984 1.1.6.2 jym datalen -= 2;
985 1.1.6.2 jym }
986 1.1.6.2 jym if (datalen > 0) {
987 1.1.6.2 jym HWRITE1(hp, SDHC_DATA, *data);
988 1.1.6.2 jym data += 1;
989 1.1.6.2 jym datalen -= 1;
990 1.1.6.2 jym }
991 1.1.6.2 jym } else {
992 1.1.6.2 jym while (datalen > 0) {
993 1.1.6.2 jym HWRITE1(hp, SDHC_DATA, *data);
994 1.1.6.2 jym data += 1;
995 1.1.6.2 jym datalen -= 1;
996 1.1.6.2 jym }
997 1.1.6.2 jym }
998 1.1.6.2 jym }
999 1.1.6.2 jym
1000 1.1.6.2 jym /* Prepare for another command. */
1001 1.1.6.2 jym static int
1002 1.1.6.2 jym sdhc_soft_reset(struct sdhc_host *hp, int mask)
1003 1.1.6.2 jym {
1004 1.1.6.2 jym int timo;
1005 1.1.6.2 jym
1006 1.1.6.2 jym DPRINTF(1,("%s: software reset reg=%08x\n", HDEVNAME(hp), mask));
1007 1.1.6.2 jym
1008 1.1.6.2 jym HWRITE1(hp, SDHC_SOFTWARE_RESET, mask);
1009 1.1.6.2 jym for (timo = 10; timo > 0; timo--) {
1010 1.1.6.2 jym if (!ISSET(HREAD1(hp, SDHC_SOFTWARE_RESET), mask))
1011 1.1.6.2 jym break;
1012 1.1.6.2 jym sdmmc_delay(10000);
1013 1.1.6.2 jym HWRITE1(hp, SDHC_SOFTWARE_RESET, 0);
1014 1.1.6.2 jym }
1015 1.1.6.2 jym if (timo == 0) {
1016 1.1.6.2 jym DPRINTF(1,("%s: timeout reg=%08x\n", HDEVNAME(hp),
1017 1.1.6.2 jym HREAD1(hp, SDHC_SOFTWARE_RESET)));
1018 1.1.6.2 jym HWRITE1(hp, SDHC_SOFTWARE_RESET, 0);
1019 1.1.6.2 jym return ETIMEDOUT;
1020 1.1.6.2 jym }
1021 1.1.6.2 jym
1022 1.1.6.2 jym return 0;
1023 1.1.6.2 jym }
1024 1.1.6.2 jym
1025 1.1.6.2 jym static int
1026 1.1.6.2 jym sdhc_wait_intr(struct sdhc_host *hp, int mask, int timo)
1027 1.1.6.2 jym {
1028 1.1.6.2 jym int status;
1029 1.1.6.2 jym
1030 1.1.6.2 jym mask |= SDHC_ERROR_INTERRUPT;
1031 1.1.6.2 jym
1032 1.1.6.2 jym mutex_enter(&hp->intr_mtx);
1033 1.1.6.2 jym status = hp->intr_status & mask;
1034 1.1.6.2 jym while (status == 0) {
1035 1.1.6.2 jym if (cv_timedwait(&hp->intr_cv, &hp->intr_mtx, timo)
1036 1.1.6.2 jym == EWOULDBLOCK) {
1037 1.1.6.2 jym status |= SDHC_ERROR_INTERRUPT;
1038 1.1.6.2 jym break;
1039 1.1.6.2 jym }
1040 1.1.6.2 jym status = hp->intr_status & mask;
1041 1.1.6.2 jym }
1042 1.1.6.2 jym hp->intr_status &= ~status;
1043 1.1.6.2 jym
1044 1.1.6.2 jym DPRINTF(2,("%s: intr status %#x error %#x\n", HDEVNAME(hp), status,
1045 1.1.6.2 jym hp->intr_error_status));
1046 1.1.6.2 jym
1047 1.1.6.2 jym /* Command timeout has higher priority than command complete. */
1048 1.1.6.2 jym if (ISSET(status, SDHC_ERROR_INTERRUPT)) {
1049 1.1.6.2 jym hp->intr_error_status = 0;
1050 1.1.6.2 jym (void)sdhc_soft_reset(hp, SDHC_RESET_DAT|SDHC_RESET_CMD);
1051 1.1.6.2 jym status = 0;
1052 1.1.6.2 jym }
1053 1.1.6.2 jym mutex_exit(&hp->intr_mtx);
1054 1.1.6.2 jym
1055 1.1.6.2 jym return status;
1056 1.1.6.2 jym }
1057 1.1.6.2 jym
1058 1.1.6.2 jym /*
1059 1.1.6.2 jym * Established by attachment driver at interrupt priority IPL_SDMMC.
1060 1.1.6.2 jym */
1061 1.1.6.2 jym int
1062 1.1.6.2 jym sdhc_intr(void *arg)
1063 1.1.6.2 jym {
1064 1.1.6.2 jym struct sdhc_softc *sc = (struct sdhc_softc *)arg;
1065 1.1.6.2 jym struct sdhc_host *hp;
1066 1.1.6.2 jym int host;
1067 1.1.6.2 jym int done = 0;
1068 1.1.6.2 jym uint16_t status;
1069 1.1.6.2 jym uint16_t error;
1070 1.1.6.2 jym
1071 1.1.6.2 jym /* We got an interrupt, but we don't know from which slot. */
1072 1.1.6.2 jym for (host = 0; host < sc->sc_nhosts; host++) {
1073 1.1.6.2 jym hp = sc->sc_host[host];
1074 1.1.6.2 jym if (hp == NULL)
1075 1.1.6.2 jym continue;
1076 1.1.6.2 jym
1077 1.1.6.2 jym /* Find out which interrupts are pending. */
1078 1.1.6.2 jym status = HREAD2(hp, SDHC_NINTR_STATUS);
1079 1.1.6.2 jym if (!ISSET(status, SDHC_NINTR_STATUS_MASK))
1080 1.1.6.2 jym continue; /* no interrupt for us */
1081 1.1.6.2 jym
1082 1.1.6.2 jym /* Acknowledge the interrupts we are about to handle. */
1083 1.1.6.2 jym HWRITE2(hp, SDHC_NINTR_STATUS, status);
1084 1.1.6.2 jym DPRINTF(2,("%s: interrupt status=%x\n", HDEVNAME(hp),
1085 1.1.6.2 jym status));
1086 1.1.6.2 jym
1087 1.1.6.2 jym if (!ISSET(status, SDHC_NINTR_STATUS_MASK))
1088 1.1.6.2 jym continue;
1089 1.1.6.2 jym
1090 1.1.6.2 jym /* Claim this interrupt. */
1091 1.1.6.2 jym done = 1;
1092 1.1.6.2 jym
1093 1.1.6.2 jym /*
1094 1.1.6.2 jym * Service error interrupts.
1095 1.1.6.2 jym */
1096 1.1.6.2 jym if (ISSET(status, SDHC_ERROR_INTERRUPT)) {
1097 1.1.6.2 jym /* Acknowledge error interrupts. */
1098 1.1.6.2 jym error = HREAD2(hp, SDHC_EINTR_STATUS);
1099 1.1.6.2 jym HWRITE2(hp, SDHC_EINTR_STATUS, error);
1100 1.1.6.2 jym DPRINTF(2,("%s: error interrupt, status=%x\n",
1101 1.1.6.2 jym HDEVNAME(hp), error));
1102 1.1.6.2 jym
1103 1.1.6.2 jym if (ISSET(error, SDHC_CMD_TIMEOUT_ERROR|
1104 1.1.6.2 jym SDHC_DATA_TIMEOUT_ERROR)) {
1105 1.1.6.2 jym hp->intr_error_status |= error;
1106 1.1.6.2 jym hp->intr_status |= status;
1107 1.1.6.2 jym cv_broadcast(&hp->intr_cv);
1108 1.1.6.2 jym }
1109 1.1.6.2 jym }
1110 1.1.6.2 jym
1111 1.1.6.2 jym /*
1112 1.1.6.2 jym * Wake up the sdmmc event thread to scan for cards.
1113 1.1.6.2 jym */
1114 1.1.6.2 jym if (ISSET(status, SDHC_CARD_REMOVAL|SDHC_CARD_INSERTION))
1115 1.1.6.2 jym sdmmc_needs_discover(hp->sdmmc);
1116 1.1.6.2 jym
1117 1.1.6.2 jym /*
1118 1.1.6.2 jym * Wake up the blocking process to service command
1119 1.1.6.2 jym * related interrupt(s).
1120 1.1.6.2 jym */
1121 1.1.6.2 jym if (ISSET(status, SDHC_BUFFER_READ_READY|
1122 1.1.6.2 jym SDHC_BUFFER_WRITE_READY|SDHC_COMMAND_COMPLETE|
1123 1.1.6.2 jym SDHC_TRANSFER_COMPLETE|SDHC_DMA_INTERRUPT)) {
1124 1.1.6.2 jym hp->intr_status |= status;
1125 1.1.6.2 jym cv_broadcast(&hp->intr_cv);
1126 1.1.6.2 jym }
1127 1.1.6.2 jym
1128 1.1.6.2 jym /*
1129 1.1.6.2 jym * Service SD card interrupts.
1130 1.1.6.2 jym */
1131 1.1.6.2 jym if (ISSET(status, SDHC_CARD_INTERRUPT)) {
1132 1.1.6.2 jym DPRINTF(0,("%s: card interrupt\n", HDEVNAME(hp)));
1133 1.1.6.2 jym HCLR2(hp, SDHC_NINTR_STATUS_EN, SDHC_CARD_INTERRUPT);
1134 1.1.6.2 jym sdmmc_card_intr(hp->sdmmc);
1135 1.1.6.2 jym }
1136 1.1.6.2 jym }
1137 1.1.6.2 jym
1138 1.1.6.2 jym return done;
1139 1.1.6.2 jym }
1140 1.1.6.2 jym
1141 1.1.6.2 jym #ifdef SDHC_DEBUG
1142 1.1.6.2 jym void
1143 1.1.6.2 jym sdhc_dump_regs(struct sdhc_host *hp)
1144 1.1.6.2 jym {
1145 1.1.6.2 jym
1146 1.1.6.2 jym printf("0x%02x PRESENT_STATE: %x\n", SDHC_PRESENT_STATE,
1147 1.1.6.2 jym HREAD4(hp, SDHC_PRESENT_STATE));
1148 1.1.6.2 jym printf("0x%02x POWER_CTL: %x\n", SDHC_POWER_CTL,
1149 1.1.6.2 jym HREAD1(hp, SDHC_POWER_CTL));
1150 1.1.6.2 jym printf("0x%02x NINTR_STATUS: %x\n", SDHC_NINTR_STATUS,
1151 1.1.6.2 jym HREAD2(hp, SDHC_NINTR_STATUS));
1152 1.1.6.2 jym printf("0x%02x EINTR_STATUS: %x\n", SDHC_EINTR_STATUS,
1153 1.1.6.2 jym HREAD2(hp, SDHC_EINTR_STATUS));
1154 1.1.6.2 jym printf("0x%02x NINTR_STATUS_EN: %x\n", SDHC_NINTR_STATUS_EN,
1155 1.1.6.2 jym HREAD2(hp, SDHC_NINTR_STATUS_EN));
1156 1.1.6.2 jym printf("0x%02x EINTR_STATUS_EN: %x\n", SDHC_EINTR_STATUS_EN,
1157 1.1.6.2 jym HREAD2(hp, SDHC_EINTR_STATUS_EN));
1158 1.1.6.2 jym printf("0x%02x NINTR_SIGNAL_EN: %x\n", SDHC_NINTR_SIGNAL_EN,
1159 1.1.6.2 jym HREAD2(hp, SDHC_NINTR_SIGNAL_EN));
1160 1.1.6.2 jym printf("0x%02x EINTR_SIGNAL_EN: %x\n", SDHC_EINTR_SIGNAL_EN,
1161 1.1.6.2 jym HREAD2(hp, SDHC_EINTR_SIGNAL_EN));
1162 1.1.6.2 jym printf("0x%02x CAPABILITIES: %x\n", SDHC_CAPABILITIES,
1163 1.1.6.2 jym HREAD4(hp, SDHC_CAPABILITIES));
1164 1.1.6.2 jym printf("0x%02x MAX_CAPABILITIES: %x\n", SDHC_MAX_CAPABILITIES,
1165 1.1.6.2 jym HREAD4(hp, SDHC_MAX_CAPABILITIES));
1166 1.1.6.2 jym }
1167 1.1.6.2 jym #endif
1168