ld_sdmmc.c revision 1.34 1 1.34 mlelstv /* $NetBSD: ld_sdmmc.c,v 1.34 2017/08/20 15:58:43 mlelstv Exp $ */
2 1.1 nonaka
3 1.1 nonaka /*
4 1.1 nonaka * Copyright (c) 2008 KIYOHARA Takashi
5 1.1 nonaka * All rights reserved.
6 1.1 nonaka *
7 1.1 nonaka * Redistribution and use in source and binary forms, with or without
8 1.1 nonaka * modification, are permitted provided that the following conditions
9 1.1 nonaka * are met:
10 1.1 nonaka * 1. Redistributions of source code must retain the above copyright
11 1.1 nonaka * notice, this list of conditions and the following disclaimer.
12 1.1 nonaka * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 nonaka * notice, this list of conditions and the following disclaimer in the
14 1.1 nonaka * documentation and/or other materials provided with the distribution.
15 1.1 nonaka *
16 1.1 nonaka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 nonaka * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 1.1 nonaka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 1.1 nonaka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 1.1 nonaka * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 1.1 nonaka * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 1.1 nonaka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 nonaka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 1.1 nonaka * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 1.1 nonaka * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 nonaka * POSSIBILITY OF SUCH DAMAGE.
27 1.1 nonaka *
28 1.1 nonaka */
29 1.1 nonaka
30 1.1 nonaka #include <sys/cdefs.h>
31 1.34 mlelstv __KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v 1.34 2017/08/20 15:58:43 mlelstv Exp $");
32 1.1 nonaka
33 1.9 matt #ifdef _KERNEL_OPT
34 1.9 matt #include "opt_sdmmc.h"
35 1.9 matt #endif
36 1.1 nonaka
37 1.1 nonaka #include <sys/param.h>
38 1.1 nonaka #include <sys/systm.h>
39 1.1 nonaka #include <sys/kernel.h>
40 1.1 nonaka #include <sys/device.h>
41 1.1 nonaka #include <sys/buf.h>
42 1.1 nonaka #include <sys/bufq.h>
43 1.1 nonaka #include <sys/bus.h>
44 1.1 nonaka #include <sys/endian.h>
45 1.1 nonaka #include <sys/dkio.h>
46 1.1 nonaka #include <sys/disk.h>
47 1.25 martin #include <sys/disklabel.h>
48 1.3 nonaka #include <sys/kthread.h>
49 1.25 martin #include <sys/syslog.h>
50 1.23 pgoyette #include <sys/module.h>
51 1.27 jmcneill #include <sys/pcq.h>
52 1.1 nonaka
53 1.1 nonaka #include <dev/ldvar.h>
54 1.1 nonaka
55 1.1 nonaka #include <dev/sdmmc/sdmmcvar.h>
56 1.1 nonaka
57 1.23 pgoyette #include "ioconf.h"
58 1.23 pgoyette
59 1.14 jmcneill #ifdef LD_SDMMC_DEBUG
60 1.1 nonaka #define DPRINTF(s) printf s
61 1.1 nonaka #else
62 1.1 nonaka #define DPRINTF(s) /**/
63 1.1 nonaka #endif
64 1.1 nonaka
65 1.24 kiyohara #define LD_SDMMC_IORETRIES 5 /* number of retries before giving up */
66 1.24 kiyohara #define RECOVERYTIME hz/2 /* time to wait before retrying a cmd */
67 1.24 kiyohara
68 1.33 jmcneill #define LD_SDMMC_MAXQUEUECNT 4 /* number of queued bio requests */
69 1.33 jmcneill #define LD_SDMMC_MAXTASKCNT 8 /* number of tasks in task pool */
70 1.33 jmcneill
71 1.1 nonaka struct ld_sdmmc_softc;
72 1.1 nonaka
73 1.1 nonaka struct ld_sdmmc_task {
74 1.1 nonaka struct sdmmc_task task;
75 1.1 nonaka
76 1.1 nonaka struct ld_sdmmc_softc *task_sc;
77 1.33 jmcneill
78 1.1 nonaka struct buf *task_bp;
79 1.24 kiyohara int task_retries; /* number of xfer retry */
80 1.24 kiyohara struct callout task_restart_ch;
81 1.1 nonaka };
82 1.1 nonaka
83 1.1 nonaka struct ld_sdmmc_softc {
84 1.1 nonaka struct ld_softc sc_ld;
85 1.1 nonaka int sc_hwunit;
86 1.1 nonaka
87 1.1 nonaka struct sdmmc_function *sc_sf;
88 1.33 jmcneill struct ld_sdmmc_task sc_task[LD_SDMMC_MAXTASKCNT];
89 1.27 jmcneill pcq_t *sc_freeq;
90 1.33 jmcneill
91 1.33 jmcneill struct evcnt sc_ev_discard; /* discard counter */
92 1.33 jmcneill struct evcnt sc_ev_discarderr; /* discard error counter */
93 1.33 jmcneill struct evcnt sc_ev_discardbusy; /* discard busy counter */
94 1.1 nonaka };
95 1.1 nonaka
96 1.2 cegger static int ld_sdmmc_match(device_t, cfdata_t, void *);
97 1.1 nonaka static void ld_sdmmc_attach(device_t, device_t, void *);
98 1.1 nonaka static int ld_sdmmc_detach(device_t, int);
99 1.1 nonaka
100 1.1 nonaka static int ld_sdmmc_dump(struct ld_softc *, void *, int, int);
101 1.1 nonaka static int ld_sdmmc_start(struct ld_softc *, struct buf *);
102 1.24 kiyohara static void ld_sdmmc_restart(void *);
103 1.34 mlelstv static int ld_sdmmc_discard(struct ld_softc *, struct buf *);
104 1.31 jmcneill static int ld_sdmmc_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
105 1.1 nonaka
106 1.3 nonaka static void ld_sdmmc_doattach(void *);
107 1.1 nonaka static void ld_sdmmc_dobio(void *);
108 1.33 jmcneill static void ld_sdmmc_dodiscard(void *);
109 1.1 nonaka
110 1.1 nonaka CFATTACH_DECL_NEW(ld_sdmmc, sizeof(struct ld_sdmmc_softc),
111 1.1 nonaka ld_sdmmc_match, ld_sdmmc_attach, ld_sdmmc_detach, NULL);
112 1.1 nonaka
113 1.1 nonaka
114 1.1 nonaka /* ARGSUSED */
115 1.1 nonaka static int
116 1.2 cegger ld_sdmmc_match(device_t parent, cfdata_t match, void *aux)
117 1.1 nonaka {
118 1.1 nonaka struct sdmmc_softc *sdmsc = device_private(parent);
119 1.1 nonaka
120 1.1 nonaka if (ISSET(sdmsc->sc_flags, SMF_MEM_MODE))
121 1.1 nonaka return 1;
122 1.1 nonaka return 0;
123 1.1 nonaka }
124 1.1 nonaka
125 1.1 nonaka /* ARGSUSED */
126 1.1 nonaka static void
127 1.1 nonaka ld_sdmmc_attach(device_t parent, device_t self, void *aux)
128 1.1 nonaka {
129 1.1 nonaka struct ld_sdmmc_softc *sc = device_private(self);
130 1.1 nonaka struct sdmmc_attach_args *sa = aux;
131 1.1 nonaka struct ld_softc *ld = &sc->sc_ld;
132 1.24 kiyohara struct ld_sdmmc_task *task;
133 1.3 nonaka struct lwp *lwp;
134 1.24 kiyohara int i;
135 1.1 nonaka
136 1.1 nonaka ld->sc_dv = self;
137 1.1 nonaka
138 1.11 jakllsch aprint_normal(": <0x%02x:0x%04x:%s:0x%02x:0x%08x:0x%03x>\n",
139 1.11 jakllsch sa->sf->cid.mid, sa->sf->cid.oid, sa->sf->cid.pnm,
140 1.11 jakllsch sa->sf->cid.rev, sa->sf->cid.psn, sa->sf->cid.mdt);
141 1.1 nonaka aprint_naive("\n");
142 1.1 nonaka
143 1.33 jmcneill evcnt_attach_dynamic(&sc->sc_ev_discard, EVCNT_TYPE_MISC,
144 1.33 jmcneill NULL, device_xname(self), "sdmmc discard count");
145 1.33 jmcneill evcnt_attach_dynamic(&sc->sc_ev_discarderr, EVCNT_TYPE_MISC,
146 1.33 jmcneill NULL, device_xname(self), "sdmmc discard errors");
147 1.33 jmcneill evcnt_attach_dynamic(&sc->sc_ev_discardbusy, EVCNT_TYPE_MISC,
148 1.33 jmcneill NULL, device_xname(self), "sdmmc discard busy");
149 1.33 jmcneill
150 1.27 jmcneill const int ntask = __arraycount(sc->sc_task);
151 1.27 jmcneill sc->sc_freeq = pcq_create(ntask, KM_SLEEP);
152 1.27 jmcneill for (i = 0; i < ntask; i++) {
153 1.24 kiyohara task = &sc->sc_task[i];
154 1.24 kiyohara task->task_sc = sc;
155 1.27 jmcneill callout_init(&task->task_restart_ch, CALLOUT_MPSAFE);
156 1.27 jmcneill pcq_put(sc->sc_freeq, task);
157 1.24 kiyohara }
158 1.20 mlelstv
159 1.1 nonaka sc->sc_hwunit = 0; /* always 0? */
160 1.1 nonaka sc->sc_sf = sa->sf;
161 1.1 nonaka
162 1.32 mlelstv ld->sc_flags = LDF_ENABLED | LDF_MPSAFE;
163 1.1 nonaka ld->sc_secperunit = sc->sc_sf->csd.capacity;
164 1.4 nonaka ld->sc_secsize = SDMMC_SECTOR_SIZE;
165 1.1 nonaka ld->sc_maxxfer = MAXPHYS;
166 1.20 mlelstv ld->sc_maxqueuecnt = LD_SDMMC_MAXQUEUECNT;
167 1.1 nonaka ld->sc_dump = ld_sdmmc_dump;
168 1.1 nonaka ld->sc_start = ld_sdmmc_start;
169 1.28 jmcneill ld->sc_discard = ld_sdmmc_discard;
170 1.31 jmcneill ld->sc_ioctl = ld_sdmmc_ioctl;
171 1.1 nonaka
172 1.3 nonaka /*
173 1.30 mlelstv * Defer attachment of ld + disk subsystem to a thread.
174 1.30 mlelstv *
175 1.30 mlelstv * This is necessary because wedge autodiscover needs to
176 1.30 mlelstv * open and call into the ld driver, which could deadlock
177 1.30 mlelstv * when the sdmmc driver isn't ready in early bootstrap.
178 1.30 mlelstv *
179 1.30 mlelstv * Don't mark thread as MPSAFE to keep aprint output sane.
180 1.3 nonaka */
181 1.12 christos config_pending_incr(self);
182 1.29 jmcneill if (kthread_create(PRI_NONE, 0, NULL,
183 1.3 nonaka ld_sdmmc_doattach, sc, &lwp, "%sattach", device_xname(self))) {
184 1.3 nonaka aprint_error_dev(self, "couldn't create thread\n");
185 1.3 nonaka }
186 1.3 nonaka }
187 1.3 nonaka
188 1.3 nonaka static void
189 1.3 nonaka ld_sdmmc_doattach(void *arg)
190 1.3 nonaka {
191 1.3 nonaka struct ld_sdmmc_softc *sc = (struct ld_sdmmc_softc *)arg;
192 1.3 nonaka struct ld_softc *ld = &sc->sc_ld;
193 1.6 kiyohara struct sdmmc_softc *ssc = device_private(device_parent(ld->sc_dv));
194 1.31 jmcneill const u_int cache_size = sc->sc_sf->ext_csd.cache_size;
195 1.31 jmcneill char buf[sizeof("9999 KB")];
196 1.3 nonaka
197 1.22 jdolecek ldattach(ld, BUFQ_DISK_DEFAULT_STRAT);
198 1.19 jmcneill aprint_normal_dev(ld->sc_dv, "%d-bit width,", sc->sc_sf->width);
199 1.19 jmcneill if (ssc->sc_transfer_mode != NULL)
200 1.19 jmcneill aprint_normal(" %s,", ssc->sc_transfer_mode);
201 1.31 jmcneill if (cache_size > 0) {
202 1.31 jmcneill format_bytes(buf, sizeof(buf), cache_size);
203 1.31 jmcneill aprint_normal(" %s cache%s,", buf,
204 1.31 jmcneill ISSET(sc->sc_sf->flags, SFF_CACHE_ENABLED) ? "" :
205 1.31 jmcneill " (disabled)");
206 1.31 jmcneill }
207 1.6 kiyohara if ((ssc->sc_busclk / 1000) != 0)
208 1.6 kiyohara aprint_normal(" %u.%03u MHz\n",
209 1.6 kiyohara ssc->sc_busclk / 1000, ssc->sc_busclk % 1000);
210 1.6 kiyohara else
211 1.6 kiyohara aprint_normal(" %u KHz\n", ssc->sc_busclk % 1000);
212 1.12 christos config_pending_decr(ld->sc_dv);
213 1.3 nonaka kthread_exit(0);
214 1.1 nonaka }
215 1.1 nonaka
216 1.1 nonaka static int
217 1.1 nonaka ld_sdmmc_detach(device_t dev, int flags)
218 1.1 nonaka {
219 1.1 nonaka struct ld_sdmmc_softc *sc = device_private(dev);
220 1.1 nonaka struct ld_softc *ld = &sc->sc_ld;
221 1.24 kiyohara int rv, i;
222 1.1 nonaka
223 1.1 nonaka if ((rv = ldbegindetach(ld, flags)) != 0)
224 1.1 nonaka return rv;
225 1.1 nonaka ldenddetach(ld);
226 1.1 nonaka
227 1.24 kiyohara for (i = 0; i < __arraycount(sc->sc_task); i++)
228 1.24 kiyohara callout_destroy(&sc->sc_task[i].task_restart_ch);
229 1.24 kiyohara
230 1.27 jmcneill pcq_destroy(sc->sc_freeq);
231 1.33 jmcneill evcnt_detach(&sc->sc_ev_discard);
232 1.33 jmcneill evcnt_detach(&sc->sc_ev_discarderr);
233 1.33 jmcneill evcnt_detach(&sc->sc_ev_discardbusy);
234 1.27 jmcneill
235 1.1 nonaka return 0;
236 1.1 nonaka }
237 1.1 nonaka
238 1.1 nonaka static int
239 1.1 nonaka ld_sdmmc_start(struct ld_softc *ld, struct buf *bp)
240 1.1 nonaka {
241 1.1 nonaka struct ld_sdmmc_softc *sc = device_private(ld->sc_dv);
242 1.27 jmcneill struct ld_sdmmc_task *task = pcq_get(sc->sc_freeq);
243 1.20 mlelstv
244 1.27 jmcneill if (task == NULL)
245 1.27 jmcneill return EAGAIN;
246 1.1 nonaka
247 1.1 nonaka task->task_bp = bp;
248 1.24 kiyohara task->task_retries = 0;
249 1.1 nonaka sdmmc_init_task(&task->task, ld_sdmmc_dobio, task);
250 1.1 nonaka
251 1.1 nonaka sdmmc_add_task(sc->sc_sf->sc, &task->task);
252 1.1 nonaka
253 1.1 nonaka return 0;
254 1.1 nonaka }
255 1.1 nonaka
256 1.1 nonaka static void
257 1.24 kiyohara ld_sdmmc_restart(void *arg)
258 1.24 kiyohara {
259 1.24 kiyohara struct ld_sdmmc_task *task = (struct ld_sdmmc_task *)arg;
260 1.24 kiyohara struct ld_sdmmc_softc *sc = task->task_sc;
261 1.24 kiyohara struct buf *bp = task->task_bp;
262 1.24 kiyohara
263 1.24 kiyohara bp->b_resid = bp->b_bcount;
264 1.24 kiyohara
265 1.24 kiyohara sdmmc_add_task(sc->sc_sf->sc, &task->task);
266 1.24 kiyohara }
267 1.24 kiyohara
268 1.24 kiyohara static void
269 1.1 nonaka ld_sdmmc_dobio(void *arg)
270 1.1 nonaka {
271 1.1 nonaka struct ld_sdmmc_task *task = (struct ld_sdmmc_task *)arg;
272 1.1 nonaka struct ld_sdmmc_softc *sc = task->task_sc;
273 1.1 nonaka struct buf *bp = task->task_bp;
274 1.18 mlelstv int error;
275 1.1 nonaka
276 1.1 nonaka /*
277 1.1 nonaka * I/O operation
278 1.1 nonaka */
279 1.1 nonaka DPRINTF(("%s: I/O operation (dir=%s, blkno=0x%jx, bcnt=0x%x)\n",
280 1.1 nonaka device_xname(sc->sc_ld.sc_dv), bp->b_flags & B_READ ? "IN" : "OUT",
281 1.1 nonaka bp->b_rawblkno, bp->b_bcount));
282 1.1 nonaka
283 1.1 nonaka /* is everything done in terms of blocks? */
284 1.1 nonaka if (bp->b_rawblkno >= sc->sc_sf->csd.capacity) {
285 1.1 nonaka /* trying to read or write past end of device */
286 1.13 mlelstv aprint_error_dev(sc->sc_ld.sc_dv,
287 1.13 mlelstv "blkno 0x%" PRIu64 " exceeds capacity %d\n",
288 1.13 mlelstv bp->b_rawblkno, sc->sc_sf->csd.capacity);
289 1.13 mlelstv bp->b_error = EINVAL;
290 1.1 nonaka bp->b_resid = bp->b_bcount;
291 1.26 jmcneill
292 1.26 jmcneill goto done;
293 1.1 nonaka }
294 1.1 nonaka
295 1.1 nonaka if (bp->b_flags & B_READ)
296 1.1 nonaka error = sdmmc_mem_read_block(sc->sc_sf, bp->b_rawblkno,
297 1.1 nonaka bp->b_data, bp->b_bcount);
298 1.1 nonaka else
299 1.1 nonaka error = sdmmc_mem_write_block(sc->sc_sf, bp->b_rawblkno,
300 1.1 nonaka bp->b_data, bp->b_bcount);
301 1.1 nonaka if (error) {
302 1.24 kiyohara if (task->task_retries < LD_SDMMC_IORETRIES) {
303 1.24 kiyohara struct dk_softc *dksc = &sc->sc_ld.sc_dksc;
304 1.24 kiyohara struct cfdriver *cd = device_cfdriver(dksc->sc_dev);
305 1.24 kiyohara
306 1.24 kiyohara diskerr(bp, cd->cd_name, "error", LOG_PRINTF, 0,
307 1.24 kiyohara dksc->sc_dkdev.dk_label);
308 1.24 kiyohara printf(", retrying\n");
309 1.24 kiyohara task->task_retries++;
310 1.24 kiyohara callout_reset(&task->task_restart_ch, RECOVERYTIME,
311 1.24 kiyohara ld_sdmmc_restart, task);
312 1.24 kiyohara return;
313 1.24 kiyohara }
314 1.13 mlelstv bp->b_error = error;
315 1.1 nonaka bp->b_resid = bp->b_bcount;
316 1.1 nonaka } else {
317 1.1 nonaka bp->b_resid = 0;
318 1.1 nonaka }
319 1.1 nonaka
320 1.26 jmcneill done:
321 1.27 jmcneill pcq_put(sc->sc_freeq, task);
322 1.24 kiyohara
323 1.1 nonaka lddone(&sc->sc_ld, bp);
324 1.1 nonaka }
325 1.1 nonaka
326 1.1 nonaka static int
327 1.1 nonaka ld_sdmmc_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
328 1.1 nonaka {
329 1.1 nonaka struct ld_sdmmc_softc *sc = device_private(ld->sc_dv);
330 1.1 nonaka
331 1.1 nonaka return sdmmc_mem_write_block(sc->sc_sf, blkno, data,
332 1.1 nonaka blkcnt * ld->sc_secsize);
333 1.1 nonaka }
334 1.23 pgoyette
335 1.33 jmcneill static void
336 1.33 jmcneill ld_sdmmc_dodiscard(void *arg)
337 1.33 jmcneill {
338 1.33 jmcneill struct ld_sdmmc_task *task = arg;
339 1.33 jmcneill struct ld_sdmmc_softc *sc = task->task_sc;
340 1.34 mlelstv struct buf *bp = task->task_bp;
341 1.34 mlelstv uint32_t sblkno, nblks;
342 1.33 jmcneill int error;
343 1.33 jmcneill
344 1.34 mlelstv /* first and last block to erase */
345 1.34 mlelstv sblkno = bp->b_rawblkno;
346 1.34 mlelstv nblks = howmany(bp->b_bcount, sc->sc_ld.sc_secsize);
347 1.34 mlelstv
348 1.33 jmcneill /* An error from discard is non-fatal */
349 1.34 mlelstv error = sdmmc_mem_discard(sc->sc_sf, sblkno, sblkno + nblks - 1);
350 1.33 jmcneill if (error != 0)
351 1.33 jmcneill sc->sc_ev_discarderr.ev_count++;
352 1.33 jmcneill else
353 1.33 jmcneill sc->sc_ev_discard.ev_count++;
354 1.34 mlelstv pcq_put(sc->sc_freeq, task);
355 1.33 jmcneill
356 1.34 mlelstv if (error)
357 1.34 mlelstv bp->b_error = error;
358 1.34 mlelstv
359 1.34 mlelstv lddiscardend(&sc->sc_ld, bp);
360 1.33 jmcneill }
361 1.33 jmcneill
362 1.28 jmcneill static int
363 1.34 mlelstv ld_sdmmc_discard(struct ld_softc *ld, struct buf *bp)
364 1.28 jmcneill {
365 1.28 jmcneill struct ld_sdmmc_softc *sc = device_private(ld->sc_dv);
366 1.33 jmcneill struct ld_sdmmc_task *task = pcq_get(sc->sc_freeq);
367 1.33 jmcneill
368 1.33 jmcneill if (task == NULL) {
369 1.33 jmcneill sc->sc_ev_discardbusy.ev_count++;
370 1.33 jmcneill return 0;
371 1.33 jmcneill }
372 1.28 jmcneill
373 1.34 mlelstv task->task_bp = bp;
374 1.33 jmcneill
375 1.33 jmcneill sdmmc_init_task(&task->task, ld_sdmmc_dodiscard, task);
376 1.33 jmcneill
377 1.33 jmcneill sdmmc_add_task(sc->sc_sf->sc, &task->task);
378 1.33 jmcneill
379 1.33 jmcneill return 0;
380 1.28 jmcneill }
381 1.28 jmcneill
382 1.31 jmcneill static int
383 1.31 jmcneill ld_sdmmc_ioctl(struct ld_softc *ld, u_long cmd, void *addr, int32_t flag,
384 1.31 jmcneill bool poll)
385 1.31 jmcneill {
386 1.31 jmcneill struct ld_sdmmc_softc *sc = device_private(ld->sc_dv);
387 1.31 jmcneill
388 1.31 jmcneill switch (cmd) {
389 1.31 jmcneill case DIOCCACHESYNC:
390 1.31 jmcneill return sdmmc_mem_flush_cache(sc->sc_sf, poll);
391 1.31 jmcneill default:
392 1.31 jmcneill return EPASSTHROUGH;
393 1.31 jmcneill }
394 1.31 jmcneill }
395 1.31 jmcneill
396 1.23 pgoyette MODULE(MODULE_CLASS_DRIVER, ld_sdmmc, "ld");
397 1.23 pgoyette
398 1.23 pgoyette #ifdef _MODULE
399 1.23 pgoyette /*
400 1.23 pgoyette * XXX Don't allow ioconf.c to redefine the "struct cfdriver ld_cd"
401 1.23 pgoyette * XXX it will be defined in the common-code module
402 1.23 pgoyette */
403 1.23 pgoyette #undef CFDRIVER_DECL
404 1.23 pgoyette #define CFDRIVER_DECL(name, class, attr)
405 1.23 pgoyette #include "ioconf.c"
406 1.23 pgoyette #endif
407 1.23 pgoyette
408 1.23 pgoyette static int
409 1.23 pgoyette ld_sdmmc_modcmd(modcmd_t cmd, void *opaque)
410 1.23 pgoyette {
411 1.23 pgoyette #ifdef _MODULE
412 1.23 pgoyette /*
413 1.23 pgoyette * We ignore the cfdriver_vec[] that ioconf provides, since
414 1.23 pgoyette * the cfdrivers are attached already.
415 1.23 pgoyette */
416 1.23 pgoyette static struct cfdriver * const no_cfdriver_vec[] = { NULL };
417 1.23 pgoyette #endif
418 1.23 pgoyette int error = 0;
419 1.23 pgoyette
420 1.23 pgoyette #ifdef _MODULE
421 1.23 pgoyette switch (cmd) {
422 1.23 pgoyette case MODULE_CMD_INIT:
423 1.23 pgoyette error = config_init_component(no_cfdriver_vec,
424 1.23 pgoyette cfattach_ioconf_ld_sdmmc, cfdata_ioconf_ld_sdmmc);
425 1.23 pgoyette break;
426 1.23 pgoyette case MODULE_CMD_FINI:
427 1.23 pgoyette error = config_fini_component(no_cfdriver_vec,
428 1.23 pgoyette cfattach_ioconf_ld_sdmmc, cfdata_ioconf_ld_sdmmc);
429 1.23 pgoyette break;
430 1.23 pgoyette default:
431 1.23 pgoyette error = ENOTTY;
432 1.23 pgoyette break;
433 1.23 pgoyette }
434 1.23 pgoyette #endif
435 1.23 pgoyette
436 1.23 pgoyette return error;
437 1.23 pgoyette }
438