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