sdmmc.c revision 1.1.6.2 1 1.1.6.2 jym /* $NetBSD: sdmmc.c,v 1.1.6.2 2009/05/13 17:21:29 jym Exp $ */
2 1.1.6.2 jym /* $OpenBSD: sdmmc.c,v 1.18 2009/01/09 10:58:38 jsg 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 * Copyright (c) 2007-2009 NONAKA Kimihiro <nonaka (at) netbsd.org>
22 1.1.6.2 jym * All rights reserved.
23 1.1.6.2 jym *
24 1.1.6.2 jym * Redistribution and use in source and binary forms, with or without
25 1.1.6.2 jym * modification, are permitted provided that the following conditions
26 1.1.6.2 jym * are met:
27 1.1.6.2 jym * 1. Redistributions of source code must retain the above copyright
28 1.1.6.2 jym * notice, this list of conditions and the following disclaimer.
29 1.1.6.2 jym * 2. Redistributions in binary form must reproduce the above copyright
30 1.1.6.2 jym * notice, this list of conditions and the following disclaimer in the
31 1.1.6.2 jym * documentation and/or other materials provided with the distribution.
32 1.1.6.2 jym *
33 1.1.6.2 jym * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
34 1.1.6.2 jym * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 1.1.6.2 jym * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 1.1.6.2 jym * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
37 1.1.6.2 jym * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38 1.1.6.2 jym * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 1.1.6.2 jym * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 1.1.6.2 jym * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41 1.1.6.2 jym * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42 1.1.6.2 jym * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 1.1.6.2 jym * SUCH DAMAGE.
44 1.1.6.2 jym */
45 1.1.6.2 jym
46 1.1.6.2 jym /*
47 1.1.6.2 jym * Host controller independent SD/MMC bus driver based on information
48 1.1.6.2 jym * from SanDisk SD Card Product Manual Revision 2.2 (SanDisk), SDIO
49 1.1.6.2 jym * Simple Specification Version 1.0 (SDIO) and the Linux "mmc" driver.
50 1.1.6.2 jym */
51 1.1.6.2 jym
52 1.1.6.2 jym #include <sys/cdefs.h>
53 1.1.6.2 jym __KERNEL_RCSID(0, "$NetBSD: sdmmc.c,v 1.1.6.2 2009/05/13 17:21:29 jym Exp $");
54 1.1.6.2 jym
55 1.1.6.2 jym #include <sys/param.h>
56 1.1.6.2 jym #include <sys/device.h>
57 1.1.6.2 jym #include <sys/kernel.h>
58 1.1.6.2 jym #include <sys/kthread.h>
59 1.1.6.2 jym #include <sys/malloc.h>
60 1.1.6.2 jym #include <sys/proc.h>
61 1.1.6.2 jym #include <sys/systm.h>
62 1.1.6.2 jym
63 1.1.6.2 jym #include <dev/sdmmc/sdmmc_ioreg.h>
64 1.1.6.2 jym #include <dev/sdmmc/sdmmcchip.h>
65 1.1.6.2 jym #include <dev/sdmmc/sdmmcreg.h>
66 1.1.6.2 jym #include <dev/sdmmc/sdmmcvar.h>
67 1.1.6.2 jym
68 1.1.6.2 jym #ifdef SDMMC_DEBUG
69 1.1.6.2 jym int sdmmcdebug = 1;
70 1.1.6.2 jym static void sdmmc_dump_command(struct sdmmc_softc *, struct sdmmc_command *);
71 1.1.6.2 jym #define DPRINTF(n,s) do { if ((n) <= sdmmcdebug) printf s; } while (0)
72 1.1.6.2 jym #else
73 1.1.6.2 jym #define DPRINTF(n,s) do {} while (0)
74 1.1.6.2 jym #endif
75 1.1.6.2 jym
76 1.1.6.2 jym #define DEVNAME(sc) SDMMCDEVNAME(sc)
77 1.1.6.2 jym
78 1.1.6.2 jym static int sdmmc_match(device_t, cfdata_t, void *);
79 1.1.6.2 jym static void sdmmc_attach(device_t, device_t, void *);
80 1.1.6.2 jym static int sdmmc_detach(device_t, int);
81 1.1.6.2 jym
82 1.1.6.2 jym CFATTACH_DECL_NEW(sdmmc, sizeof(struct sdmmc_softc),
83 1.1.6.2 jym sdmmc_match, sdmmc_attach, sdmmc_detach, NULL);
84 1.1.6.2 jym
85 1.1.6.2 jym static void sdmmc_doattach(device_t);
86 1.1.6.2 jym static void sdmmc_task_thread(void *);
87 1.1.6.2 jym static void sdmmc_discover_task(void *);
88 1.1.6.2 jym static void sdmmc_card_attach(struct sdmmc_softc *);
89 1.1.6.2 jym static void sdmmc_card_detach(struct sdmmc_softc *, int);
90 1.1.6.2 jym static int sdmmc_print(void *, const char *);
91 1.1.6.2 jym static int sdmmc_enable(struct sdmmc_softc *);
92 1.1.6.2 jym static void sdmmc_disable(struct sdmmc_softc *);
93 1.1.6.2 jym static int sdmmc_scan(struct sdmmc_softc *);
94 1.1.6.2 jym static int sdmmc_init(struct sdmmc_softc *);
95 1.1.6.2 jym
96 1.1.6.2 jym static int
97 1.1.6.2 jym sdmmc_match(device_t parent, cfdata_t cf, void *aux)
98 1.1.6.2 jym {
99 1.1.6.2 jym struct sdmmcbus_attach_args *saa = (struct sdmmcbus_attach_args *)aux;
100 1.1.6.2 jym
101 1.1.6.2 jym if (strcmp(saa->saa_busname, cf->cf_name) == 0)
102 1.1.6.2 jym return 1;
103 1.1.6.2 jym return 0;
104 1.1.6.2 jym }
105 1.1.6.2 jym
106 1.1.6.2 jym static void
107 1.1.6.2 jym sdmmc_attach(device_t parent, device_t self, void *aux)
108 1.1.6.2 jym {
109 1.1.6.2 jym struct sdmmc_softc *sc = device_private(self);
110 1.1.6.2 jym struct sdmmcbus_attach_args *saa = (struct sdmmcbus_attach_args *)aux;
111 1.1.6.2 jym int error;
112 1.1.6.2 jym
113 1.1.6.2 jym aprint_normal("\n");
114 1.1.6.2 jym aprint_naive("\n");
115 1.1.6.2 jym
116 1.1.6.2 jym sc->sc_dev = self;
117 1.1.6.2 jym sc->sc_sct = saa->saa_sct;
118 1.1.6.2 jym sc->sc_sch = saa->saa_sch;
119 1.1.6.2 jym sc->sc_dmat = saa->saa_dmat;
120 1.1.6.2 jym sc->sc_clkmin = saa->saa_clkmin;
121 1.1.6.2 jym sc->sc_clkmax = saa->saa_clkmax;
122 1.1.6.2 jym sc->sc_busclk = sc->sc_clkmax;
123 1.1.6.2 jym sc->sc_buswidth = 1;
124 1.1.6.2 jym sc->sc_caps = saa->saa_caps;
125 1.1.6.2 jym
126 1.1.6.2 jym if (ISSET(sc->sc_caps, SMC_CAPS_DMA)) {
127 1.1.6.2 jym error = bus_dmamap_create(sc->sc_dmat, MAXPHYS, SDMMC_MAXNSEGS,
128 1.1.6.2 jym MAXPHYS, 0, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW, &sc->sc_dmap);
129 1.1.6.2 jym if (error) {
130 1.1.6.2 jym aprint_error_dev(sc->sc_dev,
131 1.1.6.2 jym "couldn't create dma map. (error=%d)\n", error);
132 1.1.6.2 jym return;
133 1.1.6.2 jym }
134 1.1.6.2 jym }
135 1.1.6.2 jym
136 1.1.6.2 jym SIMPLEQ_INIT(&sc->sf_head);
137 1.1.6.2 jym TAILQ_INIT(&sc->sc_tskq);
138 1.1.6.2 jym TAILQ_INIT(&sc->sc_intrq);
139 1.1.6.2 jym
140 1.1.6.2 jym sdmmc_init_task(&sc->sc_discover_task, sdmmc_discover_task, sc);
141 1.1.6.2 jym sdmmc_init_task(&sc->sc_intr_task, sdmmc_intr_task, sc);
142 1.1.6.2 jym
143 1.1.6.2 jym mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_SDMMC);
144 1.1.6.2 jym mutex_init(&sc->sc_tskq_mtx, MUTEX_DEFAULT, IPL_SDMMC);
145 1.1.6.2 jym mutex_init(&sc->sc_discover_task_mtx, MUTEX_DEFAULT, IPL_SDMMC);
146 1.1.6.2 jym mutex_init(&sc->sc_intr_task_mtx, MUTEX_DEFAULT, IPL_SDMMC);
147 1.1.6.2 jym cv_init(&sc->sc_tskq_cv, "mmctaskq");
148 1.1.6.2 jym
149 1.1.6.2 jym if (!pmf_device_register(self, NULL, NULL)) {
150 1.1.6.2 jym aprint_error_dev(self, "couldn't establish power handler\n");
151 1.1.6.2 jym }
152 1.1.6.2 jym
153 1.1.6.2 jym SET(sc->sc_flags, SMF_INITED);
154 1.1.6.2 jym
155 1.1.6.2 jym /*
156 1.1.6.2 jym * Create the event thread that will attach and detach cards
157 1.1.6.2 jym * and perform other lengthy operations.
158 1.1.6.2 jym */
159 1.1.6.2 jym config_pending_incr();
160 1.1.6.2 jym config_interrupts(self, sdmmc_doattach);
161 1.1.6.2 jym }
162 1.1.6.2 jym
163 1.1.6.2 jym static int
164 1.1.6.2 jym sdmmc_detach(device_t self, int flags)
165 1.1.6.2 jym {
166 1.1.6.2 jym struct sdmmc_softc *sc = device_private(self);
167 1.1.6.2 jym int error;
168 1.1.6.2 jym
169 1.1.6.2 jym mutex_enter(&sc->sc_tskq_mtx);
170 1.1.6.2 jym sc->sc_dying = 1;
171 1.1.6.2 jym cv_signal(&sc->sc_tskq_cv);
172 1.1.6.2 jym while (sc->sc_tskq_lwp != NULL)
173 1.1.6.2 jym cv_wait(&sc->sc_tskq_cv, &sc->sc_tskq_mtx);
174 1.1.6.2 jym mutex_exit(&sc->sc_tskq_mtx);
175 1.1.6.2 jym
176 1.1.6.2 jym pmf_device_deregister(self);
177 1.1.6.2 jym
178 1.1.6.2 jym error = config_detach_children(self, flags);
179 1.1.6.2 jym if (error)
180 1.1.6.2 jym return error;
181 1.1.6.2 jym return 0;
182 1.1.6.2 jym }
183 1.1.6.2 jym
184 1.1.6.2 jym static void
185 1.1.6.2 jym sdmmc_doattach(device_t dev)
186 1.1.6.2 jym {
187 1.1.6.2 jym struct sdmmc_softc *sc = device_private(dev);
188 1.1.6.2 jym
189 1.1.6.2 jym if (kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL,
190 1.1.6.2 jym sdmmc_task_thread, sc, &sc->sc_tskq_lwp, "%s", device_xname(dev))) {
191 1.1.6.2 jym aprint_error_dev(dev, "couldn't create task thread\n");
192 1.1.6.2 jym }
193 1.1.6.2 jym }
194 1.1.6.2 jym
195 1.1.6.2 jym void
196 1.1.6.2 jym sdmmc_add_task(struct sdmmc_softc *sc, struct sdmmc_task *task)
197 1.1.6.2 jym {
198 1.1.6.2 jym
199 1.1.6.2 jym mutex_enter(&sc->sc_tskq_mtx);
200 1.1.6.2 jym task->onqueue = 1;
201 1.1.6.2 jym task->sc = sc;
202 1.1.6.2 jym TAILQ_INSERT_TAIL(&sc->sc_tskq, task, next);
203 1.1.6.2 jym cv_broadcast(&sc->sc_tskq_cv);
204 1.1.6.2 jym mutex_exit(&sc->sc_tskq_mtx);
205 1.1.6.2 jym }
206 1.1.6.2 jym
207 1.1.6.2 jym static inline void
208 1.1.6.2 jym sdmmc_del_task1(struct sdmmc_softc *sc, struct sdmmc_task *task)
209 1.1.6.2 jym {
210 1.1.6.2 jym
211 1.1.6.2 jym TAILQ_REMOVE(&sc->sc_tskq, task, next);
212 1.1.6.2 jym task->sc = NULL;
213 1.1.6.2 jym task->onqueue = 0;
214 1.1.6.2 jym }
215 1.1.6.2 jym
216 1.1.6.2 jym void
217 1.1.6.2 jym sdmmc_del_task(struct sdmmc_task *task)
218 1.1.6.2 jym {
219 1.1.6.2 jym struct sdmmc_softc *sc = (struct sdmmc_softc *)task->sc;
220 1.1.6.2 jym
221 1.1.6.2 jym if (sc != NULL) {
222 1.1.6.2 jym mutex_enter(&sc->sc_tskq_mtx);
223 1.1.6.2 jym sdmmc_del_task1(sc, task);
224 1.1.6.2 jym mutex_exit(&sc->sc_tskq_mtx);
225 1.1.6.2 jym }
226 1.1.6.2 jym }
227 1.1.6.2 jym
228 1.1.6.2 jym static void
229 1.1.6.2 jym sdmmc_task_thread(void *arg)
230 1.1.6.2 jym {
231 1.1.6.2 jym struct sdmmc_softc *sc = (struct sdmmc_softc *)arg;
232 1.1.6.2 jym struct sdmmc_task *task;
233 1.1.6.2 jym
234 1.1.6.2 jym sdmmc_discover_task(sc);
235 1.1.6.2 jym config_pending_decr();
236 1.1.6.2 jym
237 1.1.6.2 jym mutex_enter(&sc->sc_tskq_mtx);
238 1.1.6.2 jym for (;;) {
239 1.1.6.2 jym task = TAILQ_FIRST(&sc->sc_tskq);
240 1.1.6.2 jym if (task != NULL) {
241 1.1.6.2 jym sdmmc_del_task1(sc, task);
242 1.1.6.2 jym mutex_exit(&sc->sc_tskq_mtx);
243 1.1.6.2 jym (*task->func)(task->arg);
244 1.1.6.2 jym mutex_enter(&sc->sc_tskq_mtx);
245 1.1.6.2 jym } else {
246 1.1.6.2 jym /* Check for the exit condition. */
247 1.1.6.2 jym if (sc->sc_dying)
248 1.1.6.2 jym break;
249 1.1.6.2 jym cv_wait(&sc->sc_tskq_cv, &sc->sc_tskq_mtx);
250 1.1.6.2 jym }
251 1.1.6.2 jym }
252 1.1.6.2 jym /* time to die. */
253 1.1.6.2 jym sc->sc_dying = 0;
254 1.1.6.2 jym if (ISSET(sc->sc_flags, SMF_CARD_PRESENT))
255 1.1.6.2 jym sdmmc_card_detach(sc, DETACH_FORCE);
256 1.1.6.2 jym sc->sc_tskq_lwp = NULL;
257 1.1.6.2 jym cv_broadcast(&sc->sc_tskq_cv);
258 1.1.6.2 jym mutex_exit(&sc->sc_tskq_mtx);
259 1.1.6.2 jym kthread_exit(0);
260 1.1.6.2 jym }
261 1.1.6.2 jym
262 1.1.6.2 jym void
263 1.1.6.2 jym sdmmc_needs_discover(device_t dev)
264 1.1.6.2 jym {
265 1.1.6.2 jym struct sdmmc_softc *sc = device_private(dev);
266 1.1.6.2 jym
267 1.1.6.2 jym if (!ISSET(sc->sc_flags, SMF_INITED))
268 1.1.6.2 jym return;
269 1.1.6.2 jym
270 1.1.6.2 jym mutex_enter(&sc->sc_discover_task_mtx);
271 1.1.6.2 jym if (!sdmmc_task_pending(&sc->sc_discover_task))
272 1.1.6.2 jym sdmmc_add_task(sc, &sc->sc_discover_task);
273 1.1.6.2 jym mutex_exit(&sc->sc_discover_task_mtx);
274 1.1.6.2 jym }
275 1.1.6.2 jym
276 1.1.6.2 jym static void
277 1.1.6.2 jym sdmmc_discover_task(void *arg)
278 1.1.6.2 jym {
279 1.1.6.2 jym struct sdmmc_softc *sc = (struct sdmmc_softc *)arg;
280 1.1.6.2 jym
281 1.1.6.2 jym if (sdmmc_chip_card_detect(sc->sc_sct, sc->sc_sch)) {
282 1.1.6.2 jym if (!ISSET(sc->sc_flags, SMF_CARD_PRESENT)) {
283 1.1.6.2 jym SET(sc->sc_flags, SMF_CARD_PRESENT);
284 1.1.6.2 jym sdmmc_card_attach(sc);
285 1.1.6.2 jym }
286 1.1.6.2 jym } else {
287 1.1.6.2 jym if (ISSET(sc->sc_flags, SMF_CARD_PRESENT)) {
288 1.1.6.2 jym CLR(sc->sc_flags, SMF_CARD_PRESENT);
289 1.1.6.2 jym sdmmc_card_detach(sc, DETACH_FORCE);
290 1.1.6.2 jym }
291 1.1.6.2 jym }
292 1.1.6.2 jym }
293 1.1.6.2 jym
294 1.1.6.2 jym /*
295 1.1.6.2 jym * Called from process context when a card is present.
296 1.1.6.2 jym */
297 1.1.6.2 jym static void
298 1.1.6.2 jym sdmmc_card_attach(struct sdmmc_softc *sc)
299 1.1.6.2 jym {
300 1.1.6.2 jym struct sdmmc_function *sf;
301 1.1.6.2 jym struct sdmmc_attach_args saa;
302 1.1.6.2 jym int error;
303 1.1.6.2 jym
304 1.1.6.2 jym DPRINTF(1,("%s: attach card\n", DEVNAME(sc)));
305 1.1.6.2 jym
306 1.1.6.2 jym CLR(sc->sc_flags, SMF_CARD_ATTACHED);
307 1.1.6.2 jym
308 1.1.6.2 jym /*
309 1.1.6.2 jym * Power up the card (or card stack).
310 1.1.6.2 jym */
311 1.1.6.2 jym error = sdmmc_enable(sc);
312 1.1.6.2 jym if (error) {
313 1.1.6.2 jym aprint_error_dev(sc->sc_dev, "couldn't enable card\n");
314 1.1.6.2 jym goto err;
315 1.1.6.2 jym }
316 1.1.6.2 jym
317 1.1.6.2 jym /*
318 1.1.6.2 jym * Scan for I/O functions and memory cards on the bus,
319 1.1.6.2 jym * allocating a sdmmc_function structure for each.
320 1.1.6.2 jym */
321 1.1.6.2 jym error = sdmmc_scan(sc);
322 1.1.6.2 jym if (error) {
323 1.1.6.2 jym aprint_error_dev(sc->sc_dev, "no functions\n");
324 1.1.6.2 jym goto err;
325 1.1.6.2 jym }
326 1.1.6.2 jym
327 1.1.6.2 jym /*
328 1.1.6.2 jym * Set SD/MMC bus clock.
329 1.1.6.2 jym */
330 1.1.6.2 jym #ifdef SDMMC_DEBUG
331 1.1.6.2 jym if ((sc->sc_busclk / 1000) != 0) {
332 1.1.6.2 jym DPRINTF(1,("%s: bus clock: %u.%03u MHz\n", DEVNAME(sc),
333 1.1.6.2 jym sc->sc_busclk / 1000, sc->sc_busclk % 1000));
334 1.1.6.2 jym } else {
335 1.1.6.2 jym DPRINTF(1,("%s: bus clock: %u KHz\n", DEVNAME(sc),
336 1.1.6.2 jym sc->sc_busclk % 1000));
337 1.1.6.2 jym }
338 1.1.6.2 jym #endif
339 1.1.6.2 jym (void)sdmmc_chip_bus_clock(sc->sc_sct, sc->sc_sch, sc->sc_busclk);
340 1.1.6.2 jym
341 1.1.6.2 jym /*
342 1.1.6.2 jym * Initialize the I/O functions and memory cards.
343 1.1.6.2 jym */
344 1.1.6.2 jym error = sdmmc_init(sc);
345 1.1.6.2 jym if (error) {
346 1.1.6.2 jym aprint_error_dev(sc->sc_dev, "init failed\n");
347 1.1.6.2 jym goto err;
348 1.1.6.2 jym }
349 1.1.6.2 jym
350 1.1.6.2 jym SIMPLEQ_FOREACH(sf, &sc->sf_head, sf_list) {
351 1.1.6.2 jym if (ISSET(sc->sc_flags, SMF_IO_MODE) && sf->number < 1)
352 1.1.6.2 jym continue;
353 1.1.6.2 jym
354 1.1.6.2 jym memset(&saa, 0, sizeof saa);
355 1.1.6.2 jym saa.manufacturer = sf->cis.manufacturer;
356 1.1.6.2 jym saa.product = sf->cis.product;
357 1.1.6.2 jym saa.sf = sf;
358 1.1.6.2 jym
359 1.1.6.2 jym sf->child =
360 1.1.6.2 jym config_found_ia(sc->sc_dev, "sdmmc", &saa, sdmmc_print);
361 1.1.6.2 jym }
362 1.1.6.2 jym
363 1.1.6.2 jym SET(sc->sc_flags, SMF_CARD_ATTACHED);
364 1.1.6.2 jym return;
365 1.1.6.2 jym
366 1.1.6.2 jym err:
367 1.1.6.2 jym sdmmc_card_detach(sc, DETACH_FORCE);
368 1.1.6.2 jym }
369 1.1.6.2 jym
370 1.1.6.2 jym /*
371 1.1.6.2 jym * Called from process context with DETACH_* flags from <sys/device.h>
372 1.1.6.2 jym * when cards are gone.
373 1.1.6.2 jym */
374 1.1.6.2 jym static void
375 1.1.6.2 jym sdmmc_card_detach(struct sdmmc_softc *sc, int flags)
376 1.1.6.2 jym {
377 1.1.6.2 jym struct sdmmc_function *sf, *sfnext;
378 1.1.6.2 jym
379 1.1.6.2 jym DPRINTF(1,("%s: detach card\n", DEVNAME(sc)));
380 1.1.6.2 jym
381 1.1.6.2 jym if (ISSET(sc->sc_flags, SMF_CARD_ATTACHED)) {
382 1.1.6.2 jym SIMPLEQ_FOREACH(sf, &sc->sf_head, sf_list) {
383 1.1.6.2 jym if (sf->child != NULL) {
384 1.1.6.2 jym config_detach(sf->child, DETACH_FORCE);
385 1.1.6.2 jym sf->child = NULL;
386 1.1.6.2 jym }
387 1.1.6.2 jym }
388 1.1.6.2 jym
389 1.1.6.2 jym KASSERT(TAILQ_EMPTY(&sc->sc_intrq));
390 1.1.6.2 jym
391 1.1.6.2 jym CLR(sc->sc_flags, SMF_CARD_ATTACHED);
392 1.1.6.2 jym }
393 1.1.6.2 jym
394 1.1.6.2 jym /* Power down. */
395 1.1.6.2 jym sdmmc_disable(sc);
396 1.1.6.2 jym
397 1.1.6.2 jym /* Free all sdmmc_function structures. */
398 1.1.6.2 jym for (sf = SIMPLEQ_FIRST(&sc->sf_head); sf != NULL; sf = sfnext) {
399 1.1.6.2 jym sfnext = SIMPLEQ_NEXT(sf, sf_list);
400 1.1.6.2 jym sdmmc_function_free(sf);
401 1.1.6.2 jym }
402 1.1.6.2 jym SIMPLEQ_INIT(&sc->sf_head);
403 1.1.6.2 jym sc->sc_function_count = 0;
404 1.1.6.2 jym sc->sc_fn0 = NULL;
405 1.1.6.2 jym }
406 1.1.6.2 jym
407 1.1.6.2 jym static int
408 1.1.6.2 jym sdmmc_print(void *aux, const char *pnp)
409 1.1.6.2 jym {
410 1.1.6.2 jym struct sdmmc_attach_args *sa = aux;
411 1.1.6.2 jym struct sdmmc_function *sf = sa->sf;
412 1.1.6.2 jym struct sdmmc_cis *cis = &sf->sc->sc_fn0->cis;
413 1.1.6.2 jym int i;
414 1.1.6.2 jym
415 1.1.6.2 jym if (pnp) {
416 1.1.6.2 jym if (sf->number == 0)
417 1.1.6.2 jym return QUIET;
418 1.1.6.2 jym
419 1.1.6.2 jym for (i = 0; i < 4 && cis->cis1_info[i]; i++)
420 1.1.6.2 jym printf("%s%s", i ? ", " : "\"", cis->cis1_info[i]);
421 1.1.6.2 jym if (i != 0)
422 1.1.6.2 jym printf("\"");
423 1.1.6.2 jym
424 1.1.6.2 jym if (cis->manufacturer != SDMMC_VENDOR_INVALID &&
425 1.1.6.2 jym cis->product != SDMMC_PRODUCT_INVALID) {
426 1.1.6.2 jym printf("%s(", i ? " " : "");
427 1.1.6.2 jym if (cis->manufacturer != SDMMC_VENDOR_INVALID)
428 1.1.6.2 jym printf("manufacturer 0x%x%s",
429 1.1.6.2 jym cis->manufacturer,
430 1.1.6.2 jym cis->product == SDMMC_PRODUCT_INVALID ?
431 1.1.6.2 jym "" : ", ");
432 1.1.6.2 jym if (cis->product != SDMMC_PRODUCT_INVALID)
433 1.1.6.2 jym printf("product 0x%x", cis->product);
434 1.1.6.2 jym printf(")");
435 1.1.6.2 jym }
436 1.1.6.2 jym printf("%sat %s", i ? " " : "", pnp);
437 1.1.6.2 jym }
438 1.1.6.2 jym if (sf->number > 0)
439 1.1.6.2 jym printf(" function %d", sf->number);
440 1.1.6.2 jym
441 1.1.6.2 jym if (!pnp) {
442 1.1.6.2 jym for (i = 0; i < 3 && cis->cis1_info[i]; i++)
443 1.1.6.2 jym printf("%s%s", i ? ", " : " \"", cis->cis1_info[i]);
444 1.1.6.2 jym if (i != 0)
445 1.1.6.2 jym printf("\"");
446 1.1.6.2 jym }
447 1.1.6.2 jym return UNCONF;
448 1.1.6.2 jym }
449 1.1.6.2 jym
450 1.1.6.2 jym static int
451 1.1.6.2 jym sdmmc_enable(struct sdmmc_softc *sc)
452 1.1.6.2 jym {
453 1.1.6.2 jym int error;
454 1.1.6.2 jym
455 1.1.6.2 jym /*
456 1.1.6.2 jym * Calculate the equivalent of the card OCR from the host
457 1.1.6.2 jym * capabilities and select the maximum supported bus voltage.
458 1.1.6.2 jym */
459 1.1.6.2 jym error = sdmmc_chip_bus_power(sc->sc_sct, sc->sc_sch,
460 1.1.6.2 jym sdmmc_chip_host_ocr(sc->sc_sct, sc->sc_sch));
461 1.1.6.2 jym if (error) {
462 1.1.6.2 jym aprint_error_dev(sc->sc_dev, "couldn't supply bus power\n");
463 1.1.6.2 jym goto out;
464 1.1.6.2 jym }
465 1.1.6.2 jym
466 1.1.6.2 jym /*
467 1.1.6.2 jym * Select the minimum clock frequency.
468 1.1.6.2 jym */
469 1.1.6.2 jym error = sdmmc_chip_bus_clock(sc->sc_sct, sc->sc_sch, SDMMC_SDCLK_400K);
470 1.1.6.2 jym if (error) {
471 1.1.6.2 jym aprint_error_dev(sc->sc_dev, "couldn't supply clock\n");
472 1.1.6.2 jym goto out;
473 1.1.6.2 jym }
474 1.1.6.2 jym
475 1.1.6.2 jym /* XXX wait for card to power up */
476 1.1.6.2 jym sdmmc_delay(100000);
477 1.1.6.2 jym
478 1.1.6.2 jym /* Initialize SD I/O card function(s). */
479 1.1.6.2 jym error = sdmmc_io_enable(sc);
480 1.1.6.2 jym if (error)
481 1.1.6.2 jym goto out;
482 1.1.6.2 jym
483 1.1.6.2 jym /* Initialize SD/MMC memory card(s). */
484 1.1.6.2 jym if (ISSET(sc->sc_flags, SMF_MEM_MODE))
485 1.1.6.2 jym error = sdmmc_mem_enable(sc);
486 1.1.6.2 jym
487 1.1.6.2 jym out:
488 1.1.6.2 jym if (error)
489 1.1.6.2 jym sdmmc_disable(sc);
490 1.1.6.2 jym return error;
491 1.1.6.2 jym }
492 1.1.6.2 jym
493 1.1.6.2 jym static void
494 1.1.6.2 jym sdmmc_disable(struct sdmmc_softc *sc)
495 1.1.6.2 jym {
496 1.1.6.2 jym /* XXX complete commands if card is still present. */
497 1.1.6.2 jym
498 1.1.6.2 jym /* Make sure no card is still selected. */
499 1.1.6.2 jym (void)sdmmc_select_card(sc, NULL);
500 1.1.6.2 jym
501 1.1.6.2 jym /* Turn off bus power and clock. */
502 1.1.6.2 jym (void)sdmmc_chip_bus_width(sc->sc_sct, sc->sc_sch, 1);
503 1.1.6.2 jym (void)sdmmc_chip_bus_clock(sc->sc_sct, sc->sc_sch, SDMMC_SDCLK_OFF);
504 1.1.6.2 jym (void)sdmmc_chip_bus_power(sc->sc_sct, sc->sc_sch, 0);
505 1.1.6.2 jym }
506 1.1.6.2 jym
507 1.1.6.2 jym /*
508 1.1.6.2 jym * Set the lowest bus voltage supported by the card and the host.
509 1.1.6.2 jym */
510 1.1.6.2 jym int
511 1.1.6.2 jym sdmmc_set_bus_power(struct sdmmc_softc *sc, uint32_t host_ocr,
512 1.1.6.2 jym uint32_t card_ocr)
513 1.1.6.2 jym {
514 1.1.6.2 jym uint32_t bit;
515 1.1.6.2 jym
516 1.1.6.2 jym /* Mask off unsupported voltage levels and select the lowest. */
517 1.1.6.2 jym DPRINTF(1,("%s: host_ocr=%x ", DEVNAME(sc), host_ocr));
518 1.1.6.2 jym host_ocr &= card_ocr;
519 1.1.6.2 jym for (bit = 4; bit < 23; bit++) {
520 1.1.6.2 jym if (ISSET(host_ocr, (1 << bit))) {
521 1.1.6.2 jym host_ocr &= (3 << bit);
522 1.1.6.2 jym break;
523 1.1.6.2 jym }
524 1.1.6.2 jym }
525 1.1.6.2 jym DPRINTF(1,("card_ocr=%x new_ocr=%x\n", card_ocr, host_ocr));
526 1.1.6.2 jym
527 1.1.6.2 jym if (host_ocr == 0 ||
528 1.1.6.2 jym sdmmc_chip_bus_power(sc->sc_sct, sc->sc_sch, host_ocr) != 0)
529 1.1.6.2 jym return 1;
530 1.1.6.2 jym return 0;
531 1.1.6.2 jym }
532 1.1.6.2 jym
533 1.1.6.2 jym struct sdmmc_function *
534 1.1.6.2 jym sdmmc_function_alloc(struct sdmmc_softc *sc)
535 1.1.6.2 jym {
536 1.1.6.2 jym struct sdmmc_function *sf;
537 1.1.6.2 jym
538 1.1.6.2 jym sf = malloc(sizeof *sf, M_DEVBUF, M_WAITOK|M_ZERO);
539 1.1.6.2 jym if (sf == NULL) {
540 1.1.6.2 jym aprint_error_dev(sc->sc_dev,
541 1.1.6.2 jym "couldn't alloc memory (sdmmc function)\n");
542 1.1.6.2 jym return NULL;
543 1.1.6.2 jym }
544 1.1.6.2 jym
545 1.1.6.2 jym sf->sc = sc;
546 1.1.6.2 jym sf->number = -1;
547 1.1.6.2 jym sf->cis.manufacturer = SDMMC_VENDOR_INVALID;
548 1.1.6.2 jym sf->cis.product = SDMMC_PRODUCT_INVALID;
549 1.1.6.2 jym sf->cis.function = SDMMC_FUNCTION_INVALID;
550 1.1.6.2 jym
551 1.1.6.2 jym return sf;
552 1.1.6.2 jym }
553 1.1.6.2 jym
554 1.1.6.2 jym void
555 1.1.6.2 jym sdmmc_function_free(struct sdmmc_function *sf)
556 1.1.6.2 jym {
557 1.1.6.2 jym
558 1.1.6.2 jym free(sf, M_DEVBUF);
559 1.1.6.2 jym }
560 1.1.6.2 jym
561 1.1.6.2 jym /*
562 1.1.6.2 jym * Scan for I/O functions and memory cards on the bus, allocating a
563 1.1.6.2 jym * sdmmc_function structure for each.
564 1.1.6.2 jym */
565 1.1.6.2 jym static int
566 1.1.6.2 jym sdmmc_scan(struct sdmmc_softc *sc)
567 1.1.6.2 jym {
568 1.1.6.2 jym
569 1.1.6.2 jym /* Scan for I/O functions. */
570 1.1.6.2 jym if (ISSET(sc->sc_flags, SMF_IO_MODE))
571 1.1.6.2 jym sdmmc_io_scan(sc);
572 1.1.6.2 jym
573 1.1.6.2 jym /* Scan for memory cards on the bus. */
574 1.1.6.2 jym if (ISSET(sc->sc_flags, SMF_MEM_MODE))
575 1.1.6.2 jym sdmmc_mem_scan(sc);
576 1.1.6.2 jym
577 1.1.6.2 jym /* There should be at least one function now. */
578 1.1.6.2 jym if (SIMPLEQ_EMPTY(&sc->sf_head)) {
579 1.1.6.2 jym aprint_error_dev(sc->sc_dev, "couldn't identify card\n");
580 1.1.6.2 jym return 1;
581 1.1.6.2 jym }
582 1.1.6.2 jym return 0;
583 1.1.6.2 jym }
584 1.1.6.2 jym
585 1.1.6.2 jym /*
586 1.1.6.2 jym * Initialize all the distinguished functions of the card, be it I/O
587 1.1.6.2 jym * or memory functions.
588 1.1.6.2 jym */
589 1.1.6.2 jym static int
590 1.1.6.2 jym sdmmc_init(struct sdmmc_softc *sc)
591 1.1.6.2 jym {
592 1.1.6.2 jym struct sdmmc_function *sf;
593 1.1.6.2 jym
594 1.1.6.2 jym /* Initialize all identified card functions. */
595 1.1.6.2 jym SIMPLEQ_FOREACH(sf, &sc->sf_head, sf_list) {
596 1.1.6.2 jym if (ISSET(sc->sc_flags, SMF_IO_MODE) &&
597 1.1.6.2 jym sdmmc_io_init(sc, sf) != 0) {
598 1.1.6.2 jym aprint_error_dev(sc->sc_dev, "i/o init failed\n");
599 1.1.6.2 jym }
600 1.1.6.2 jym
601 1.1.6.2 jym if (ISSET(sc->sc_flags, SMF_MEM_MODE) &&
602 1.1.6.2 jym sdmmc_mem_init(sc, sf) != 0) {
603 1.1.6.2 jym aprint_error_dev(sc->sc_dev, "mem init failed\n");
604 1.1.6.2 jym }
605 1.1.6.2 jym }
606 1.1.6.2 jym
607 1.1.6.2 jym /* Any good functions left after initialization? */
608 1.1.6.2 jym SIMPLEQ_FOREACH(sf, &sc->sf_head, sf_list) {
609 1.1.6.2 jym if (!ISSET(sf->flags, SFF_ERROR))
610 1.1.6.2 jym return 0;
611 1.1.6.2 jym }
612 1.1.6.2 jym
613 1.1.6.2 jym /* No, we should probably power down the card. */
614 1.1.6.2 jym return 1;
615 1.1.6.2 jym }
616 1.1.6.2 jym
617 1.1.6.2 jym void
618 1.1.6.2 jym sdmmc_delay(u_int usecs)
619 1.1.6.2 jym {
620 1.1.6.2 jym
621 1.1.6.2 jym delay(usecs);
622 1.1.6.2 jym }
623 1.1.6.2 jym
624 1.1.6.2 jym int
625 1.1.6.2 jym sdmmc_app_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd)
626 1.1.6.2 jym {
627 1.1.6.2 jym struct sdmmc_command acmd;
628 1.1.6.2 jym int error;
629 1.1.6.2 jym
630 1.1.6.2 jym DPRINTF(1,("sdmmc_app_command: start\n"));
631 1.1.6.2 jym
632 1.1.6.2 jym /* Don't lock */
633 1.1.6.2 jym
634 1.1.6.2 jym memset(&acmd, 0, sizeof(acmd));
635 1.1.6.2 jym acmd.c_opcode = MMC_APP_CMD;
636 1.1.6.2 jym acmd.c_arg = 0;
637 1.1.6.2 jym acmd.c_flags = SCF_CMD_AC | SCF_RSP_R1;
638 1.1.6.2 jym
639 1.1.6.2 jym error = sdmmc_mmc_command(sc, &acmd);
640 1.1.6.2 jym if (error == 0) {
641 1.1.6.2 jym if (!ISSET(MMC_R1(acmd.c_resp), MMC_R1_APP_CMD)) {
642 1.1.6.2 jym /* Card does not support application commands. */
643 1.1.6.2 jym error = ENODEV;
644 1.1.6.2 jym } else {
645 1.1.6.2 jym error = sdmmc_mmc_command(sc, cmd);
646 1.1.6.2 jym }
647 1.1.6.2 jym }
648 1.1.6.2 jym DPRINTF(1,("sdmmc_app_command: done (error=%d)\n", error));
649 1.1.6.2 jym return error;
650 1.1.6.2 jym }
651 1.1.6.2 jym
652 1.1.6.2 jym /*
653 1.1.6.2 jym * Execute MMC command and data transfers. All interactions with the
654 1.1.6.2 jym * host controller to complete the command happen in the context of
655 1.1.6.2 jym * the current process.
656 1.1.6.2 jym */
657 1.1.6.2 jym int
658 1.1.6.2 jym sdmmc_mmc_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd)
659 1.1.6.2 jym {
660 1.1.6.2 jym int error;
661 1.1.6.2 jym
662 1.1.6.2 jym DPRINTF(1,("sdmmc_mmc_command: cmd=%#x, arg=%#x, flags=%#x\n",
663 1.1.6.2 jym cmd->c_opcode, cmd->c_arg, cmd->c_flags));
664 1.1.6.2 jym
665 1.1.6.2 jym /* Don't lock */
666 1.1.6.2 jym
667 1.1.6.2 jym #if defined(DIAGNOSTIC) || defined(SDMMC_DEBUG)
668 1.1.6.2 jym if (cmd->c_data) {
669 1.1.6.2 jym if (sc->sc_card == NULL)
670 1.1.6.2 jym panic("%s: deselected card\n", DEVNAME(sc));
671 1.1.6.2 jym }
672 1.1.6.2 jym #endif
673 1.1.6.2 jym
674 1.1.6.2 jym sdmmc_chip_exec_command(sc->sc_sct, sc->sc_sch, cmd);
675 1.1.6.2 jym
676 1.1.6.2 jym #ifdef SDMMC_DEBUG
677 1.1.6.2 jym sdmmc_dump_command(sc, cmd);
678 1.1.6.2 jym #endif
679 1.1.6.2 jym
680 1.1.6.2 jym error = cmd->c_error;
681 1.1.6.2 jym
682 1.1.6.2 jym DPRINTF(1,("sdmmc_mmc_command: error=%d\n", error));
683 1.1.6.2 jym
684 1.1.6.2 jym return error;
685 1.1.6.2 jym }
686 1.1.6.2 jym
687 1.1.6.2 jym /*
688 1.1.6.2 jym * Send the "GO IDLE STATE" command.
689 1.1.6.2 jym */
690 1.1.6.2 jym void
691 1.1.6.2 jym sdmmc_go_idle_state(struct sdmmc_softc *sc)
692 1.1.6.2 jym {
693 1.1.6.2 jym struct sdmmc_command cmd;
694 1.1.6.2 jym
695 1.1.6.2 jym DPRINTF(1,("sdmmc_go_idle_state\n"));
696 1.1.6.2 jym
697 1.1.6.2 jym /* Don't lock */
698 1.1.6.2 jym
699 1.1.6.2 jym memset(&cmd, 0, sizeof(cmd));
700 1.1.6.2 jym cmd.c_opcode = MMC_GO_IDLE_STATE;
701 1.1.6.2 jym cmd.c_flags = SCF_CMD_BC | SCF_RSP_R0;
702 1.1.6.2 jym
703 1.1.6.2 jym (void)sdmmc_mmc_command(sc, &cmd);
704 1.1.6.2 jym }
705 1.1.6.2 jym
706 1.1.6.2 jym /*
707 1.1.6.2 jym * Retrieve (SD) or set (MMC) the relative card address (RCA).
708 1.1.6.2 jym */
709 1.1.6.2 jym int
710 1.1.6.2 jym sdmmc_set_relative_addr(struct sdmmc_softc *sc, struct sdmmc_function *sf)
711 1.1.6.2 jym {
712 1.1.6.2 jym struct sdmmc_command cmd;
713 1.1.6.2 jym int error;
714 1.1.6.2 jym
715 1.1.6.2 jym /* Don't lock */
716 1.1.6.2 jym
717 1.1.6.2 jym memset(&cmd, 0, sizeof(cmd));
718 1.1.6.2 jym if (ISSET(sc->sc_flags, SMF_SD_MODE)) {
719 1.1.6.2 jym cmd.c_opcode = SD_SEND_RELATIVE_ADDR;
720 1.1.6.2 jym cmd.c_flags = SCF_CMD_BCR | SCF_RSP_R6;
721 1.1.6.2 jym } else {
722 1.1.6.2 jym cmd.c_opcode = MMC_SET_RELATIVE_ADDR;
723 1.1.6.2 jym cmd.c_arg = MMC_ARG_RCA(sf->rca);
724 1.1.6.2 jym cmd.c_flags = SCF_CMD_AC | SCF_RSP_R1;
725 1.1.6.2 jym }
726 1.1.6.2 jym error = sdmmc_mmc_command(sc, &cmd);
727 1.1.6.2 jym if (error)
728 1.1.6.2 jym return error;
729 1.1.6.2 jym
730 1.1.6.2 jym if (ISSET(sc->sc_flags, SMF_SD_MODE))
731 1.1.6.2 jym sf->rca = SD_R6_RCA(cmd.c_resp);
732 1.1.6.2 jym
733 1.1.6.2 jym return 0;
734 1.1.6.2 jym }
735 1.1.6.2 jym
736 1.1.6.2 jym int
737 1.1.6.2 jym sdmmc_select_card(struct sdmmc_softc *sc, struct sdmmc_function *sf)
738 1.1.6.2 jym {
739 1.1.6.2 jym struct sdmmc_command cmd;
740 1.1.6.2 jym int error;
741 1.1.6.2 jym
742 1.1.6.2 jym /* Don't lock */
743 1.1.6.2 jym
744 1.1.6.2 jym if (sc->sc_card == sf
745 1.1.6.2 jym || (sf && sc->sc_card && sc->sc_card->rca == sf->rca)) {
746 1.1.6.2 jym sc->sc_card = sf;
747 1.1.6.2 jym return 0;
748 1.1.6.2 jym }
749 1.1.6.2 jym
750 1.1.6.2 jym memset(&cmd, 0, sizeof(cmd));
751 1.1.6.2 jym cmd.c_opcode = MMC_SELECT_CARD;
752 1.1.6.2 jym cmd.c_arg = (sf == NULL) ? 0 : MMC_ARG_RCA(sf->rca);
753 1.1.6.2 jym cmd.c_flags = SCF_CMD_AC | ((sf == NULL) ? SCF_RSP_R0 : SCF_RSP_R1);
754 1.1.6.2 jym error = sdmmc_mmc_command(sc, &cmd);
755 1.1.6.2 jym if (error == 0 || sf == NULL)
756 1.1.6.2 jym sc->sc_card = sf;
757 1.1.6.2 jym
758 1.1.6.2 jym return error;
759 1.1.6.2 jym }
760 1.1.6.2 jym
761 1.1.6.2 jym #ifdef SDMMC_DEBUG
762 1.1.6.2 jym static void
763 1.1.6.2 jym sdmmc_dump_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd)
764 1.1.6.2 jym {
765 1.1.6.2 jym int i;
766 1.1.6.2 jym
767 1.1.6.2 jym DPRINTF(1,("%s: cmd %u arg=%#x data=%p dlen=%d flags=%#x "
768 1.1.6.2 jym "proc=\"%s\" (error %d)\n",
769 1.1.6.2 jym DEVNAME(sc), cmd->c_opcode, cmd->c_arg, cmd->c_data,
770 1.1.6.2 jym cmd->c_datalen, cmd->c_flags, curproc ? curproc->p_comm : "",
771 1.1.6.2 jym cmd->c_error));
772 1.1.6.2 jym
773 1.1.6.2 jym if (cmd->c_error || sdmmcdebug < 1)
774 1.1.6.2 jym return;
775 1.1.6.2 jym
776 1.1.6.2 jym aprint_normal_dev(sc->sc_dev, "resp=");
777 1.1.6.2 jym if (ISSET(cmd->c_flags, SCF_RSP_136))
778 1.1.6.2 jym for (i = 0; i < sizeof cmd->c_resp; i++)
779 1.1.6.2 jym aprint_normal("%02x ", ((uint8_t *)cmd->c_resp)[i]);
780 1.1.6.2 jym else if (ISSET(cmd->c_flags, SCF_RSP_PRESENT))
781 1.1.6.2 jym for (i = 0; i < 4; i++)
782 1.1.6.2 jym aprint_normal("%02x ", ((uint8_t *)cmd->c_resp)[i]);
783 1.1.6.2 jym aprint_normal("\n");
784 1.1.6.2 jym }
785 1.1.6.2 jym #endif
786