2 * Copyright (c) 2014-2019 Ruslan Bukin <br@bsdpad.com>
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7 * ("CTSRD"), as part of the DARPA CRASH research programme.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * Synopsys DesignWare Mobile Storage Host Controller
33 * Chapter 14, Altera Cyclone V Device Handbook (CV-5V2 2014.07.22)
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
39 #include <sys/param.h>
40 #include <sys/systm.h>
42 #include <sys/kernel.h>
44 #include <sys/module.h>
45 #include <sys/malloc.h>
46 #include <sys/mutex.h>
48 #include <sys/queue.h>
49 #include <sys/taskqueue.h>
51 #include <dev/mmc/bridge.h>
52 #include <dev/mmc/mmcbrvar.h>
53 #include <dev/mmc/mmc_fdt_helpers.h>
55 #include <dev/fdt/fdt_common.h>
56 #include <dev/ofw/openfirm.h>
57 #include <dev/ofw/ofw_bus.h>
58 #include <dev/ofw/ofw_bus_subr.h>
60 #include <machine/bus.h>
61 #include <machine/cpu.h>
62 #include <machine/intr.h>
65 #include <dev/extres/clk/clk.h>
68 #include <dev/mmc/host/dwmmc_reg.h>
69 #include <dev/mmc/host/dwmmc_var.h>
71 #include "opt_mmccam.h"
75 #include <cam/cam_ccb.h>
76 #include <cam/cam_debug.h>
77 #include <cam/cam_sim.h>
78 #include <cam/cam_xpt_sim.h>
84 #define dprintf(fmt, args...) printf(fmt, ##args)
86 #define dprintf(x, arg...)
89 #define READ4(_sc, _reg) \
90 bus_read_4((_sc)->res[0], _reg)
91 #define WRITE4(_sc, _reg, _val) \
92 bus_write_4((_sc)->res[0], _reg, _val)
94 #define DIV_ROUND_UP(n, d) howmany(n, d)
96 #define DWMMC_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
97 #define DWMMC_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
98 #define DWMMC_LOCK_INIT(_sc) \
99 mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->dev), \
101 #define DWMMC_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx);
102 #define DWMMC_ASSERT_LOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED);
103 #define DWMMC_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED);
105 #define PENDING_CMD 0x01
106 #define PENDING_STOP 0x02
107 #define CARD_INIT_DONE 0x04
109 #define DWMMC_DATA_ERR_FLAGS (SDMMC_INTMASK_DRT | SDMMC_INTMASK_DCRC \
110 |SDMMC_INTMASK_HTO | SDMMC_INTMASK_SBE \
112 #define DWMMC_CMD_ERR_FLAGS (SDMMC_INTMASK_RTO | SDMMC_INTMASK_RCRC \
114 #define DWMMC_ERR_FLAGS (DWMMC_DATA_ERR_FLAGS | DWMMC_CMD_ERR_FLAGS \
117 #define DES0_DIC (1 << 1) /* Disable Interrupt on Completion */
118 #define DES0_LD (1 << 2) /* Last Descriptor */
119 #define DES0_FS (1 << 3) /* First Descriptor */
120 #define DES0_CH (1 << 4) /* second address CHained */
121 #define DES0_ER (1 << 5) /* End of Ring */
122 #define DES0_CES (1 << 30) /* Card Error Summary */
123 #define DES0_OWN (1 << 31) /* OWN */
125 #define DES1_BS1_MASK 0x1fff
128 uint32_t des0; /* control */
129 uint32_t des1; /* bufsize */
130 uint32_t des2; /* buf1 phys addr */
131 uint32_t des3; /* buf2 phys addr or next descr */
134 #define IDMAC_DESC_SEGS (PAGE_SIZE / (sizeof(struct idmac_desc)))
135 #define IDMAC_DESC_SIZE (sizeof(struct idmac_desc) * IDMAC_DESC_SEGS)
136 #define DEF_MSIZE 0x2 /* Burst size of multiple transaction */
137 #define IDMAC_MAX_SIZE 4096
139 static void dwmmc_next_operation(struct dwmmc_softc *);
140 static int dwmmc_setup_bus(struct dwmmc_softc *, int);
141 static int dma_done(struct dwmmc_softc *, struct mmc_command *);
142 static int dma_stop(struct dwmmc_softc *);
143 static void pio_read(struct dwmmc_softc *, struct mmc_command *);
144 static void pio_write(struct dwmmc_softc *, struct mmc_command *);
145 static void dwmmc_handle_card_present(struct dwmmc_softc *sc, bool is_present);
147 static int dwmmc_switch_vccq(device_t, device_t);
148 static void dwmmc_cam_action(struct cam_sim *, union ccb *);
149 static void dwmmc_cam_poll(struct cam_sim *);
150 static int dwmmc_cam_settran_settings(struct dwmmc_softc *, union ccb *);
151 static int dwmmc_cam_request(struct dwmmc_softc *, union ccb *);
152 static void dwmmc_cam_handle_mmcio(struct cam_sim *, union ccb *);
155 static struct resource_spec dwmmc_spec[] = {
156 { SYS_RES_MEMORY, 0, RF_ACTIVE },
157 { SYS_RES_IRQ, 0, RF_ACTIVE },
161 #define HWTYPE_MASK (0x0000ffff)
162 #define HWFLAG_MASK (0xffff << 16)
165 dwmmc_get1paddr(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
170 *(bus_addr_t *)arg = segs[0].ds_addr;
174 dwmmc_ring_setup(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
176 struct dwmmc_softc *sc;
184 dprintf("nsegs %d seg0len %lu\n", nsegs, segs[0].ds_len);
186 for (idx = 0; idx < nsegs; idx++) {
187 sc->desc_ring[idx].des0 = (DES0_OWN | DES0_DIC | DES0_CH);
188 sc->desc_ring[idx].des1 = segs[idx].ds_len & DES1_BS1_MASK;
189 sc->desc_ring[idx].des2 = segs[idx].ds_addr;
192 sc->desc_ring[idx].des0 |= DES0_FS;
194 if (idx == (nsegs - 1)) {
195 sc->desc_ring[idx].des0 &= ~(DES0_DIC | DES0_CH);
196 sc->desc_ring[idx].des0 |= DES0_LD;
202 dwmmc_ctrl_reset(struct dwmmc_softc *sc, int reset_bits)
207 reg = READ4(sc, SDMMC_CTRL);
209 WRITE4(sc, SDMMC_CTRL, reg);
211 /* Wait reset done */
212 for (i = 0; i < 100; i++) {
213 if (!(READ4(sc, SDMMC_CTRL) & reset_bits))
218 device_printf(sc->dev, "Reset failed\n");
224 dma_setup(struct dwmmc_softc *sc)
231 * Set up TX descriptor ring, descriptors, and dma maps.
233 error = bus_dma_tag_create(
234 bus_get_dma_tag(sc->dev), /* Parent tag. */
235 4096, 0, /* alignment, boundary */
236 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
237 BUS_SPACE_MAXADDR, /* highaddr */
238 NULL, NULL, /* filter, filterarg */
239 IDMAC_DESC_SIZE, 1, /* maxsize, nsegments */
240 IDMAC_DESC_SIZE, /* maxsegsize */
242 NULL, NULL, /* lockfunc, lockarg */
245 device_printf(sc->dev,
246 "could not create ring DMA tag.\n");
250 error = bus_dmamem_alloc(sc->desc_tag, (void**)&sc->desc_ring,
251 BUS_DMA_COHERENT | BUS_DMA_WAITOK | BUS_DMA_ZERO,
254 device_printf(sc->dev,
255 "could not allocate descriptor ring.\n");
259 error = bus_dmamap_load(sc->desc_tag, sc->desc_map,
260 sc->desc_ring, IDMAC_DESC_SIZE, dwmmc_get1paddr,
261 &sc->desc_ring_paddr, 0);
263 device_printf(sc->dev,
264 "could not load descriptor ring map.\n");
268 for (idx = 0; idx < IDMAC_DESC_SEGS; idx++) {
269 sc->desc_ring[idx].des0 = DES0_CH;
270 sc->desc_ring[idx].des1 = 0;
271 nidx = (idx + 1) % IDMAC_DESC_SEGS;
272 sc->desc_ring[idx].des3 = sc->desc_ring_paddr + \
273 (nidx * sizeof(struct idmac_desc));
275 sc->desc_ring[idx - 1].des3 = sc->desc_ring_paddr;
276 sc->desc_ring[idx - 1].des0 |= DES0_ER;
278 error = bus_dma_tag_create(
279 bus_get_dma_tag(sc->dev), /* Parent tag. */
280 CACHE_LINE_SIZE, 0, /* alignment, boundary */
281 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
282 BUS_SPACE_MAXADDR, /* highaddr */
283 NULL, NULL, /* filter, filterarg */
284 IDMAC_MAX_SIZE * IDMAC_DESC_SEGS, /* maxsize */
285 IDMAC_DESC_SEGS, /* nsegments */
286 IDMAC_MAX_SIZE, /* maxsegsize */
288 NULL, NULL, /* lockfunc, lockarg */
291 device_printf(sc->dev,
292 "could not create ring DMA tag.\n");
296 error = bus_dmamap_create(sc->buf_tag, 0,
299 device_printf(sc->dev,
300 "could not create TX buffer DMA map.\n");
308 dwmmc_cmd_done(struct dwmmc_softc *sc)
310 struct mmc_command *cmd;
319 cmd = &ccb->mmcio.cmd;
326 if (cmd->flags & MMC_RSP_PRESENT) {
327 if (cmd->flags & MMC_RSP_136) {
328 cmd->resp[3] = READ4(sc, SDMMC_RESP0);
329 cmd->resp[2] = READ4(sc, SDMMC_RESP1);
330 cmd->resp[1] = READ4(sc, SDMMC_RESP2);
331 cmd->resp[0] = READ4(sc, SDMMC_RESP3);
336 cmd->resp[0] = READ4(sc, SDMMC_RESP0);
342 dwmmc_tasklet(struct dwmmc_softc *sc)
344 struct mmc_command *cmd;
353 if (cmd->error != MMC_ERR_NONE || !cmd->data) {
354 dwmmc_next_operation(sc);
355 } else if (cmd->data && sc->dto_rcvd) {
356 if ((cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK ||
357 cmd->opcode == MMC_READ_MULTIPLE_BLOCK) &&
360 dwmmc_next_operation(sc);
362 dwmmc_next_operation(sc);
368 dwmmc_intr(void *arg)
370 struct mmc_command *cmd;
371 struct dwmmc_softc *sc;
380 /* First handle SDMMC controller interrupts */
381 reg = READ4(sc, SDMMC_MINTSTS);
383 dprintf("%s 0x%08x\n", __func__, reg);
385 if (reg & DWMMC_CMD_ERR_FLAGS) {
386 dprintf("cmd err 0x%08x cmd 0x%08x\n",
388 cmd->error = MMC_ERR_TIMEOUT;
391 if (reg & DWMMC_DATA_ERR_FLAGS) {
392 dprintf("data err 0x%08x cmd 0x%08x\n",
394 cmd->error = MMC_ERR_FAILED;
401 if (reg & SDMMC_INTMASK_CMD_DONE) {
406 if (reg & SDMMC_INTMASK_ACD)
409 if (reg & SDMMC_INTMASK_DTO)
412 if (reg & SDMMC_INTMASK_CD) {
413 dwmmc_handle_card_present(sc,
414 READ4(sc, SDMMC_CDETECT) == 0 ? true : false);
419 WRITE4(sc, SDMMC_RINTSTS, reg);
422 if (reg & (SDMMC_INTMASK_RXDR|SDMMC_INTMASK_DTO)) {
425 if (reg & (SDMMC_INTMASK_TXDR|SDMMC_INTMASK_DTO)) {
429 /* Now handle DMA interrupts */
430 reg = READ4(sc, SDMMC_IDSTS);
432 dprintf("dma intr 0x%08x\n", reg);
433 if (reg & (SDMMC_IDINTEN_TI | SDMMC_IDINTEN_RI)) {
434 WRITE4(sc, SDMMC_IDSTS, (SDMMC_IDINTEN_TI |
436 WRITE4(sc, SDMMC_IDSTS, SDMMC_IDINTEN_NI);
448 dwmmc_handle_card_present(struct dwmmc_softc *sc, bool is_present)
452 was_present = sc->child != NULL;
454 if (!was_present && is_present) {
455 taskqueue_enqueue_timeout(taskqueue_swi_giant,
456 &sc->card_delayed_task, -(hz / 2));
457 } else if (was_present && !is_present) {
458 taskqueue_enqueue(taskqueue_swi_giant, &sc->card_task);
463 dwmmc_card_task(void *arg, int pending __unused)
465 struct dwmmc_softc *sc = arg;
468 mmccam_start_discovery(sc->sim);
472 if (READ4(sc, SDMMC_CDETECT) == 0) {
473 if (sc->child == NULL) {
475 device_printf(sc->dev, "Card inserted\n");
477 sc->child = device_add_child(sc->dev, "mmc", -1);
480 device_set_ivars(sc->child, sc);
481 (void)device_probe_and_attach(sc->child);
486 /* Card isn't present, detach if necessary */
487 if (sc->child != NULL) {
489 device_printf(sc->dev, "Card removed\n");
492 device_delete_child(sc->dev, sc->child);
501 parse_fdt(struct dwmmc_softc *sc)
503 pcell_t dts_value[3];
511 if ((node = ofw_bus_get_node(sc->dev)) == -1)
514 /* Set some defaults for freq and supported mode */
515 sc->host.f_min = 400000;
516 sc->host.f_max = 200000000;
517 sc->host.host_ocr = MMC_OCR_320_330 | MMC_OCR_330_340;
518 sc->host.caps = MMC_CAP_HSPEED | MMC_CAP_SIGNALING_330;
519 mmc_fdt_parse(sc->dev, node, &sc->mmc_helper, &sc->host);
522 if ((len = OF_getproplen(node, "fifo-depth")) > 0) {
523 OF_getencprop(node, "fifo-depth", dts_value, len);
524 sc->fifo_depth = dts_value[0];
527 /* num-slots (Deprecated) */
529 if ((len = OF_getproplen(node, "num-slots")) > 0) {
530 device_printf(sc->dev, "num-slots property is deprecated\n");
531 OF_getencprop(node, "num-slots", dts_value, len);
532 sc->num_slots = dts_value[0];
535 /* clock-frequency */
536 if ((len = OF_getproplen(node, "clock-frequency")) > 0) {
537 OF_getencprop(node, "clock-frequency", dts_value, len);
538 bus_hz = dts_value[0];
543 /* IP block reset is optional */
544 error = hwreset_get_by_ofw_name(sc->dev, 0, "reset", &sc->hwreset);
548 device_printf(sc->dev, "Cannot get reset\n");
552 /* vmmc regulator is optional */
553 error = regulator_get_by_ofw_property(sc->dev, 0, "vmmc-supply",
558 device_printf(sc->dev, "Cannot get regulator 'vmmc-supply'\n");
562 /* vqmmc regulator is optional */
563 error = regulator_get_by_ofw_property(sc->dev, 0, "vqmmc-supply",
568 device_printf(sc->dev, "Cannot get regulator 'vqmmc-supply'\n");
572 /* Assert reset first */
573 if (sc->hwreset != NULL) {
574 error = hwreset_assert(sc->hwreset);
576 device_printf(sc->dev, "Cannot assert reset\n");
581 /* BIU (Bus Interface Unit clock) is optional */
582 error = clk_get_by_ofw_name(sc->dev, 0, "biu", &sc->biu);
586 device_printf(sc->dev, "Cannot get 'biu' clock\n");
591 error = clk_enable(sc->biu);
593 device_printf(sc->dev, "cannot enable biu clock\n");
599 * CIU (Controller Interface Unit clock) is mandatory
600 * if no clock-frequency property is given
602 error = clk_get_by_ofw_name(sc->dev, 0, "ciu", &sc->ciu);
606 device_printf(sc->dev, "Cannot get 'ciu' clock\n");
612 error = clk_set_freq(sc->ciu, bus_hz, 0);
614 device_printf(sc->dev,
615 "cannot set ciu clock to %u\n", bus_hz);
617 error = clk_enable(sc->ciu);
619 device_printf(sc->dev, "cannot enable ciu clock\n");
622 clk_get_freq(sc->ciu, &sc->bus_hz);
625 /* Enable regulators */
626 if (sc->vmmc != NULL) {
627 error = regulator_enable(sc->vmmc);
629 device_printf(sc->dev, "Cannot enable vmmc regulator\n");
633 if (sc->vqmmc != NULL) {
634 error = regulator_enable(sc->vqmmc);
636 device_printf(sc->dev, "Cannot enable vqmmc regulator\n");
641 /* Take dwmmc out of reset */
642 if (sc->hwreset != NULL) {
643 error = hwreset_deassert(sc->hwreset);
645 device_printf(sc->dev, "Cannot deassert reset\n");
649 #endif /* EXT_RESOURCES */
651 if (sc->bus_hz == 0) {
652 device_printf(sc->dev, "No bus speed provided\n");
663 dwmmc_attach(device_t dev)
665 struct dwmmc_softc *sc;
669 sc = device_get_softc(dev);
673 /* Why not to use Auto Stop? It save a hundred of irq per second */
674 sc->use_auto_stop = 1;
676 error = parse_fdt(sc);
678 device_printf(dev, "Can't get FDT property.\n");
684 if (bus_alloc_resources(dev, dwmmc_spec, sc->res)) {
685 device_printf(dev, "could not allocate resources\n");
689 /* Setup interrupt handler. */
690 error = bus_setup_intr(dev, sc->res[1], INTR_TYPE_NET | INTR_MPSAFE,
691 NULL, dwmmc_intr, sc, &sc->intr_cookie);
693 device_printf(dev, "could not setup interrupt handler.\n");
697 device_printf(dev, "Hardware version ID is %04x\n",
698 READ4(sc, SDMMC_VERID) & 0xffff);
700 /* XXX: we support operation for slot index 0 only */
702 if (sc->pwren_inverted) {
703 WRITE4(sc, SDMMC_PWREN, (0 << slot));
705 WRITE4(sc, SDMMC_PWREN, (1 << slot));
709 if (dwmmc_ctrl_reset(sc, (SDMMC_CTRL_RESET |
710 SDMMC_CTRL_FIFO_RESET |
711 SDMMC_CTRL_DMA_RESET)))
714 dwmmc_setup_bus(sc, sc->host.f_min);
716 if (sc->fifo_depth == 0) {
718 ((READ4(sc, SDMMC_FIFOTH) >> SDMMC_FIFOTH_RXWMARK_S) & 0xfff);
719 device_printf(dev, "No fifo-depth, using FIFOTH %x\n",
728 /* Install desc base */
729 WRITE4(sc, SDMMC_DBADDR, sc->desc_ring_paddr);
731 /* Enable DMA interrupts */
732 WRITE4(sc, SDMMC_IDSTS, SDMMC_IDINTEN_MASK);
733 WRITE4(sc, SDMMC_IDINTEN, (SDMMC_IDINTEN_NI |
738 /* Clear and disable interrups for a while */
739 WRITE4(sc, SDMMC_RINTSTS, 0xffffffff);
740 WRITE4(sc, SDMMC_INTMASK, 0);
742 /* Maximum timeout */
743 WRITE4(sc, SDMMC_TMOUT, 0xffffffff);
745 /* Enable interrupts */
746 WRITE4(sc, SDMMC_RINTSTS, 0xffffffff);
747 WRITE4(sc, SDMMC_INTMASK, (SDMMC_INTMASK_CMD_DONE |
754 WRITE4(sc, SDMMC_CTRL, SDMMC_CTRL_INT_ENABLE);
756 TASK_INIT(&sc->card_task, 0, dwmmc_card_task, sc);
757 TIMEOUT_TASK_INIT(taskqueue_swi_giant, &sc->card_delayed_task, 0,
758 dwmmc_card_task, sc);
762 if ((sc->devq = cam_simq_alloc(1)) == NULL) {
766 mtx_init(&sc->sim_mtx, "dwmmcsim", NULL, MTX_DEF);
767 sc->sim = cam_sim_alloc_dev(dwmmc_cam_action, dwmmc_cam_poll,
768 "dw_mmc_sim", sc, dev,
769 &sc->sim_mtx, 1, 1, sc->devq);
771 if (sc->sim == NULL) {
772 cam_simq_free(sc->devq);
773 device_printf(dev, "cannot allocate CAM SIM\n");
777 mtx_lock(&sc->sim_mtx);
778 if (xpt_bus_register(sc->sim, sc->dev, 0) != 0) {
779 device_printf(sc->dev, "cannot register SCSI pass-through bus\n");
780 cam_sim_free(sc->sim, FALSE);
781 cam_simq_free(sc->devq);
782 mtx_unlock(&sc->sim_mtx);
787 mtx_unlock(&sc->sim_mtx);
790 * Schedule a card detection as we won't get an interrupt
791 * if the card is inserted when we attach
793 dwmmc_card_task(sc, 0);
798 dwmmc_detach(device_t dev)
800 struct dwmmc_softc *sc;
803 sc = device_get_softc(dev);
805 ret = device_delete_children(dev);
809 taskqueue_drain(taskqueue_swi_giant, &sc->card_task);
810 taskqueue_drain_timeout(taskqueue_swi_giant, &sc->card_delayed_task);
812 if (sc->intr_cookie != NULL) {
813 ret = bus_teardown_intr(dev, sc->res[1], sc->intr_cookie);
817 bus_release_resources(dev, dwmmc_spec, sc->res);
819 DWMMC_LOCK_DESTROY(sc);
822 if (sc->hwreset != NULL && hwreset_deassert(sc->hwreset) != 0)
823 device_printf(sc->dev, "cannot deassert reset\n");
824 if (sc->biu != NULL && clk_disable(sc->biu) != 0)
825 device_printf(sc->dev, "cannot disable biu clock\n");
826 if (sc->ciu != NULL && clk_disable(sc->ciu) != 0)
827 device_printf(sc->dev, "cannot disable ciu clock\n");
829 if (sc->vmmc && regulator_disable(sc->vmmc) != 0)
830 device_printf(sc->dev, "Cannot disable vmmc regulator\n");
831 if (sc->vqmmc && regulator_disable(sc->vqmmc) != 0)
832 device_printf(sc->dev, "Cannot disable vqmmc regulator\n");
839 dwmmc_setup_bus(struct dwmmc_softc *sc, int freq)
845 WRITE4(sc, SDMMC_CLKENA, 0);
846 WRITE4(sc, SDMMC_CMD, (SDMMC_CMD_WAIT_PRVDATA |
847 SDMMC_CMD_UPD_CLK_ONLY | SDMMC_CMD_START));
852 device_printf(sc->dev, "Failed update clk\n");
855 } while (READ4(sc, SDMMC_CMD) & SDMMC_CMD_START);
860 WRITE4(sc, SDMMC_CLKENA, 0);
861 WRITE4(sc, SDMMC_CLKSRC, 0);
863 div = (sc->bus_hz != freq) ? DIV_ROUND_UP(sc->bus_hz, 2 * freq) : 0;
865 WRITE4(sc, SDMMC_CLKDIV, div);
866 WRITE4(sc, SDMMC_CMD, (SDMMC_CMD_WAIT_PRVDATA |
867 SDMMC_CMD_UPD_CLK_ONLY | SDMMC_CMD_START));
872 device_printf(sc->dev, "Failed to update clk");
875 } while (READ4(sc, SDMMC_CMD) & SDMMC_CMD_START);
877 WRITE4(sc, SDMMC_CLKENA, (SDMMC_CLKENA_CCLK_EN | SDMMC_CLKENA_LP));
878 WRITE4(sc, SDMMC_CMD, SDMMC_CMD_WAIT_PRVDATA |
879 SDMMC_CMD_UPD_CLK_ONLY | SDMMC_CMD_START);
884 device_printf(sc->dev, "Failed to enable clk\n");
887 } while (READ4(sc, SDMMC_CMD) & SDMMC_CMD_START);
893 dwmmc_update_ios(device_t brdev, device_t reqdev)
895 struct dwmmc_softc *sc;
900 sc = device_get_softc(brdev);
903 dprintf("Setting up clk %u bus_width %d\n",
904 ios->clock, ios->bus_width);
906 if (ios->bus_width == bus_width_8)
907 WRITE4(sc, SDMMC_CTYPE, SDMMC_CTYPE_8BIT);
908 else if (ios->bus_width == bus_width_4)
909 WRITE4(sc, SDMMC_CTYPE, SDMMC_CTYPE_4BIT);
911 WRITE4(sc, SDMMC_CTYPE, 0);
913 if ((sc->hwtype & HWTYPE_MASK) == HWTYPE_EXYNOS) {
914 /* XXX: take care about DDR or SDR use here */
915 WRITE4(sc, SDMMC_CLKSEL, sc->sdr_timing);
919 reg = READ4(sc, SDMMC_UHS_REG);
920 if (ios->timing == bus_timing_uhs_ddr50 ||
921 ios->timing == bus_timing_mmc_ddr52 ||
922 ios->timing == bus_timing_mmc_hs400)
923 reg |= (SDMMC_UHS_REG_DDR);
925 reg &= ~(SDMMC_UHS_REG_DDR);
926 WRITE4(sc, SDMMC_UHS_REG, reg);
929 ret = sc->update_ios(sc, ios);
931 dwmmc_setup_bus(sc, ios->clock);
937 dma_done(struct dwmmc_softc *sc, struct mmc_command *cmd)
939 struct mmc_data *data;
943 if (data->flags & MMC_DATA_WRITE)
944 bus_dmamap_sync(sc->buf_tag, sc->buf_map,
945 BUS_DMASYNC_POSTWRITE);
947 bus_dmamap_sync(sc->buf_tag, sc->buf_map,
948 BUS_DMASYNC_POSTREAD);
950 bus_dmamap_sync(sc->desc_tag, sc->desc_map,
951 BUS_DMASYNC_POSTWRITE);
953 bus_dmamap_unload(sc->buf_tag, sc->buf_map);
959 dma_stop(struct dwmmc_softc *sc)
963 reg = READ4(sc, SDMMC_CTRL);
964 reg &= ~(SDMMC_CTRL_USE_IDMAC);
965 reg |= (SDMMC_CTRL_DMA_RESET);
966 WRITE4(sc, SDMMC_CTRL, reg);
968 reg = READ4(sc, SDMMC_BMOD);
969 reg &= ~(SDMMC_BMOD_DE | SDMMC_BMOD_FB);
970 reg |= (SDMMC_BMOD_SWR);
971 WRITE4(sc, SDMMC_BMOD, reg);
977 dma_prepare(struct dwmmc_softc *sc, struct mmc_command *cmd)
979 struct mmc_data *data;
985 reg = READ4(sc, SDMMC_INTMASK);
986 reg &= ~(SDMMC_INTMASK_TXDR | SDMMC_INTMASK_RXDR);
987 WRITE4(sc, SDMMC_INTMASK, reg);
989 err = bus_dmamap_load(sc->buf_tag, sc->buf_map,
990 data->data, data->len, dwmmc_ring_setup,
993 panic("dmamap_load failed\n");
995 /* Ensure the device can see the desc */
996 bus_dmamap_sync(sc->desc_tag, sc->desc_map,
997 BUS_DMASYNC_PREWRITE);
999 if (data->flags & MMC_DATA_WRITE)
1000 bus_dmamap_sync(sc->buf_tag, sc->buf_map,
1001 BUS_DMASYNC_PREWRITE);
1003 bus_dmamap_sync(sc->buf_tag, sc->buf_map,
1004 BUS_DMASYNC_PREREAD);
1006 reg = (DEF_MSIZE << SDMMC_FIFOTH_MSIZE_S);
1007 reg |= ((sc->fifo_depth / 2) - 1) << SDMMC_FIFOTH_RXWMARK_S;
1008 reg |= (sc->fifo_depth / 2) << SDMMC_FIFOTH_TXWMARK_S;
1010 WRITE4(sc, SDMMC_FIFOTH, reg);
1013 reg = READ4(sc, SDMMC_CTRL);
1014 reg |= (SDMMC_CTRL_USE_IDMAC | SDMMC_CTRL_DMA_ENABLE);
1015 WRITE4(sc, SDMMC_CTRL, reg);
1018 reg = READ4(sc, SDMMC_BMOD);
1019 reg |= (SDMMC_BMOD_DE | SDMMC_BMOD_FB);
1020 WRITE4(sc, SDMMC_BMOD, reg);
1023 WRITE4(sc, SDMMC_PLDMND, 1);
1029 pio_prepare(struct dwmmc_softc *sc, struct mmc_command *cmd)
1031 struct mmc_data *data;
1037 reg = (DEF_MSIZE << SDMMC_FIFOTH_MSIZE_S);
1038 reg |= ((sc->fifo_depth / 2) - 1) << SDMMC_FIFOTH_RXWMARK_S;
1039 reg |= (sc->fifo_depth / 2) << SDMMC_FIFOTH_TXWMARK_S;
1041 WRITE4(sc, SDMMC_FIFOTH, reg);
1048 pio_read(struct dwmmc_softc *sc, struct mmc_command *cmd)
1050 struct mmc_data *data;
1051 uint32_t *p, status;
1053 if (cmd == NULL || cmd->data == NULL)
1057 if ((data->flags & MMC_DATA_READ) == 0)
1060 KASSERT((data->xfer_len & 3) == 0, ("xfer_len not aligned"));
1061 p = (uint32_t *)data->data + (data->xfer_len >> 2);
1063 while (data->xfer_len < data->len) {
1064 status = READ4(sc, SDMMC_STATUS);
1065 if (status & SDMMC_STATUS_FIFO_EMPTY)
1067 *p++ = READ4(sc, SDMMC_DATA);
1068 data->xfer_len += 4;
1071 WRITE4(sc, SDMMC_RINTSTS, SDMMC_INTMASK_RXDR);
1075 pio_write(struct dwmmc_softc *sc, struct mmc_command *cmd)
1077 struct mmc_data *data;
1078 uint32_t *p, status;
1080 if (cmd == NULL || cmd->data == NULL)
1084 if ((data->flags & MMC_DATA_WRITE) == 0)
1087 KASSERT((data->xfer_len & 3) == 0, ("xfer_len not aligned"));
1088 p = (uint32_t *)data->data + (data->xfer_len >> 2);
1090 while (data->xfer_len < data->len) {
1091 status = READ4(sc, SDMMC_STATUS);
1092 if (status & SDMMC_STATUS_FIFO_FULL)
1094 WRITE4(sc, SDMMC_DATA, *p++);
1095 data->xfer_len += 4;
1098 WRITE4(sc, SDMMC_RINTSTS, SDMMC_INTMASK_TXDR);
1102 dwmmc_start_cmd(struct dwmmc_softc *sc, struct mmc_command *cmd)
1104 struct mmc_data *data;
1108 dprintf("%s\n", __func__);
1112 if ((sc->hwtype & HWTYPE_MASK) == HWTYPE_ROCKCHIP)
1113 dwmmc_setup_bus(sc, sc->host.ios.clock);
1116 /* XXX Upper layers don't always set this */
1119 /* Begin setting up command register. */
1123 dprintf("cmd->opcode 0x%08x\n", cmd->opcode);
1125 if (cmd->opcode == MMC_STOP_TRANSMISSION ||
1126 cmd->opcode == MMC_GO_IDLE_STATE ||
1127 cmd->opcode == MMC_GO_INACTIVE_STATE)
1128 cmdr |= SDMMC_CMD_STOP_ABORT;
1129 else if (cmd->opcode != MMC_SEND_STATUS && data)
1130 cmdr |= SDMMC_CMD_WAIT_PRVDATA;
1132 /* Set up response handling. */
1133 if (MMC_RSP(cmd->flags) != MMC_RSP_NONE) {
1134 cmdr |= SDMMC_CMD_RESP_EXP;
1135 if (cmd->flags & MMC_RSP_136)
1136 cmdr |= SDMMC_CMD_RESP_LONG;
1139 if (cmd->flags & MMC_RSP_CRC)
1140 cmdr |= SDMMC_CMD_RESP_CRC;
1143 * XXX: Not all platforms want this.
1145 cmdr |= SDMMC_CMD_USE_HOLD_REG;
1147 if ((sc->flags & CARD_INIT_DONE) == 0) {
1148 sc->flags |= (CARD_INIT_DONE);
1149 cmdr |= SDMMC_CMD_SEND_INIT;
1153 if ((cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK ||
1154 cmd->opcode == MMC_READ_MULTIPLE_BLOCK) &&
1156 cmdr |= SDMMC_CMD_SEND_ASTOP;
1158 cmdr |= SDMMC_CMD_DATA_EXP;
1159 if (data->flags & MMC_DATA_STREAM)
1160 cmdr |= SDMMC_CMD_MODE_STREAM;
1161 if (data->flags & MMC_DATA_WRITE)
1162 cmdr |= SDMMC_CMD_DATA_WRITE;
1164 WRITE4(sc, SDMMC_TMOUT, 0xffffffff);
1165 WRITE4(sc, SDMMC_BYTCNT, data->len);
1166 blksz = (data->len < MMC_SECTOR_SIZE) ? \
1167 data->len : MMC_SECTOR_SIZE;
1168 WRITE4(sc, SDMMC_BLKSIZ, blksz);
1171 pio_prepare(sc, cmd);
1173 dma_prepare(sc, cmd);
1178 dprintf("cmdr 0x%08x\n", cmdr);
1180 WRITE4(sc, SDMMC_CMDARG, cmd->arg);
1182 WRITE4(sc, SDMMC_CMD, cmdr | SDMMC_CMD_START);
1186 dwmmc_next_operation(struct dwmmc_softc *sc)
1188 struct mmc_command *cmd;
1189 dprintf("%s\n", __func__);
1196 cmd = &ccb->mmcio.cmd;
1198 struct mmc_request *req;
1211 * XXX: Wait until card is still busy.
1212 * We do need this to prevent data timeouts,
1213 * mostly caused by multi-block write command
1214 * followed by single-read.
1216 while(READ4(sc, SDMMC_STATUS) & (SDMMC_STATUS_DATA_BUSY))
1219 if (sc->flags & PENDING_CMD) {
1220 sc->flags &= ~PENDING_CMD;
1221 dwmmc_start_cmd(sc, cmd);
1223 } else if (sc->flags & PENDING_STOP && !sc->use_auto_stop) {
1224 sc->flags &= ~PENDING_STOP;
1225 /// XXX: What to do with this?
1226 //dwmmc_start_cmd(sc, req->stop);
1234 (ccb->mmcio.cmd.error == 0 ? CAM_REQ_CMP : CAM_REQ_CMP_ERR);
1244 dwmmc_request(device_t brdev, device_t reqdev, struct mmc_request *req)
1246 struct dwmmc_softc *sc;
1248 sc = device_get_softc(brdev);
1250 dprintf("%s\n", __func__);
1255 sc->flags |= PENDING_CMD;
1257 if (sc->req != NULL) {
1263 sc->flags |= PENDING_CMD;
1265 sc->flags |= PENDING_STOP;
1267 dwmmc_next_operation(sc);
1274 dwmmc_get_ro(device_t brdev, device_t reqdev)
1277 dprintf("%s\n", __func__);
1283 dwmmc_acquire_host(device_t brdev, device_t reqdev)
1285 struct dwmmc_softc *sc;
1287 sc = device_get_softc(brdev);
1290 while (sc->bus_busy)
1291 msleep(sc, &sc->sc_mtx, PZERO, "dwmmcah", hz / 5);
1298 dwmmc_release_host(device_t brdev, device_t reqdev)
1300 struct dwmmc_softc *sc;
1302 sc = device_get_softc(brdev);
1312 dwmmc_read_ivar(device_t bus, device_t child, int which, uintptr_t *result)
1314 struct dwmmc_softc *sc;
1316 sc = device_get_softc(bus);
1321 case MMCBR_IVAR_BUS_MODE:
1322 *(int *)result = sc->host.ios.bus_mode;
1324 case MMCBR_IVAR_BUS_WIDTH:
1325 *(int *)result = sc->host.ios.bus_width;
1327 case MMCBR_IVAR_CHIP_SELECT:
1328 *(int *)result = sc->host.ios.chip_select;
1330 case MMCBR_IVAR_CLOCK:
1331 *(int *)result = sc->host.ios.clock;
1333 case MMCBR_IVAR_F_MIN:
1334 *(int *)result = sc->host.f_min;
1336 case MMCBR_IVAR_F_MAX:
1337 *(int *)result = sc->host.f_max;
1339 case MMCBR_IVAR_HOST_OCR:
1340 *(int *)result = sc->host.host_ocr;
1342 case MMCBR_IVAR_MODE:
1343 *(int *)result = sc->host.mode;
1345 case MMCBR_IVAR_OCR:
1346 *(int *)result = sc->host.ocr;
1348 case MMCBR_IVAR_POWER_MODE:
1349 *(int *)result = sc->host.ios.power_mode;
1351 case MMCBR_IVAR_VDD:
1352 *(int *)result = sc->host.ios.vdd;
1354 case MMCBR_IVAR_VCCQ:
1355 *(int *)result = sc->host.ios.vccq;
1357 case MMCBR_IVAR_CAPS:
1358 *(int *)result = sc->host.caps;
1360 case MMCBR_IVAR_MAX_DATA:
1361 *(int *)result = (IDMAC_MAX_SIZE * IDMAC_DESC_SEGS) / MMC_SECTOR_SIZE;
1363 case MMCBR_IVAR_TIMING:
1364 *(int *)result = sc->host.ios.timing;
1371 dwmmc_write_ivar(device_t bus, device_t child, int which, uintptr_t value)
1373 struct dwmmc_softc *sc;
1375 sc = device_get_softc(bus);
1380 case MMCBR_IVAR_BUS_MODE:
1381 sc->host.ios.bus_mode = value;
1383 case MMCBR_IVAR_BUS_WIDTH:
1384 sc->host.ios.bus_width = value;
1386 case MMCBR_IVAR_CHIP_SELECT:
1387 sc->host.ios.chip_select = value;
1389 case MMCBR_IVAR_CLOCK:
1390 sc->host.ios.clock = value;
1392 case MMCBR_IVAR_MODE:
1393 sc->host.mode = value;
1395 case MMCBR_IVAR_OCR:
1396 sc->host.ocr = value;
1398 case MMCBR_IVAR_POWER_MODE:
1399 sc->host.ios.power_mode = value;
1401 case MMCBR_IVAR_VDD:
1402 sc->host.ios.vdd = value;
1404 case MMCBR_IVAR_TIMING:
1405 sc->host.ios.timing = value;
1407 case MMCBR_IVAR_VCCQ:
1408 sc->host.ios.vccq = value;
1410 /* These are read-only */
1411 case MMCBR_IVAR_CAPS:
1412 case MMCBR_IVAR_HOST_OCR:
1413 case MMCBR_IVAR_F_MIN:
1414 case MMCBR_IVAR_F_MAX:
1415 case MMCBR_IVAR_MAX_DATA:
1422 /* Note: this function likely belongs to the specific driver impl */
1424 dwmmc_switch_vccq(device_t dev, device_t child)
1426 device_printf(dev, "This is a default impl of switch_vccq() that always fails\n");
1431 dwmmc_cam_handle_mmcio(struct cam_sim *sim, union ccb *ccb)
1433 struct dwmmc_softc *sc;
1435 sc = cam_sim_softc(sim);
1437 dwmmc_cam_request(sc, ccb);
1441 dwmmc_cam_action(struct cam_sim *sim, union ccb *ccb)
1443 struct dwmmc_softc *sc;
1445 sc = cam_sim_softc(sim);
1447 ccb->ccb_h.status = CAM_SEL_TIMEOUT;
1452 mtx_assert(&sc->sim_mtx, MA_OWNED);
1454 switch (ccb->ccb_h.func_code) {
1456 /* XXX: correctly calculate maxio here */
1457 mmc_path_inq(&ccb->cpi, "Deglitch Networks", sim, MMC_SECTOR_SIZE);
1460 case XPT_GET_TRAN_SETTINGS:
1462 struct ccb_trans_settings *cts = &ccb->cts;
1464 cts->protocol = PROTO_MMCSD;
1465 cts->protocol_version = 1;
1466 cts->transport = XPORT_MMCSD;
1467 cts->transport_version = 1;
1468 cts->xport_specific.valid = 0;
1469 cts->proto_specific.mmc.host_ocr = sc->host.host_ocr;
1470 cts->proto_specific.mmc.host_f_min = sc->host.f_min;
1471 cts->proto_specific.mmc.host_f_max = sc->host.f_max;
1472 cts->proto_specific.mmc.host_caps = sc->host.caps;
1473 /* XXX: correctly calculate host_max_data */
1474 cts->proto_specific.mmc.host_max_data = 1;
1475 memcpy(&cts->proto_specific.mmc.ios, &sc->host.ios, sizeof(struct mmc_ios));
1476 ccb->ccb_h.status = CAM_REQ_CMP;
1479 case XPT_SET_TRAN_SETTINGS:
1481 dwmmc_cam_settran_settings(sc, ccb);
1482 ccb->ccb_h.status = CAM_REQ_CMP;
1485 case XPT_RESET_BUS: {
1486 struct ccb_trans_settings_mmc *cts;
1488 cts = &ccb->cts.proto_specific.mmc;
1489 cts->ios_valid = MMC_PM;
1490 cts->ios.power_mode = power_off;
1491 /* Power off the MMC bus */
1492 if (dwmmc_cam_settran_settings(sc, ccb) != 0) {
1493 device_printf(sc->dev,"cannot power down the MMC bus\n");
1494 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1498 /* Soft Reset controller and run initialization again */
1499 if (dwmmc_ctrl_reset(sc, (SDMMC_CTRL_RESET |
1500 SDMMC_CTRL_FIFO_RESET |
1501 SDMMC_CTRL_DMA_RESET)) != 0) {
1502 device_printf(sc->dev, "cannot reset the controller\n");
1503 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1507 cts->ios_valid = MMC_PM;
1508 cts->ios.power_mode = power_on;
1509 /* Power off the MMC bus */
1510 if (dwmmc_cam_settran_settings(sc, ccb) != 0) {
1511 device_printf(sc->dev, "cannot power on the MMC bus\n");
1512 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1516 ccb->ccb_h.status = CAM_REQ_CMP;
1521 * Here is the HW-dependent part of
1522 * sending the command to the underlying h/w
1523 * At some point in the future an interrupt comes.
1524 * Then the request will be marked as completed.
1526 ccb->ccb_h.status = CAM_REQ_INPROG;
1528 dwmmc_cam_handle_mmcio(sim, ccb);
1533 ccb->ccb_h.status = CAM_REQ_INVALID;
1541 dwmmc_cam_poll(struct cam_sim *sim)
1547 dwmmc_cam_settran_settings(struct dwmmc_softc *sc, union ccb *ccb)
1549 struct mmc_ios *ios;
1550 struct mmc_ios *new_ios;
1551 struct ccb_trans_settings_mmc *cts;
1554 ios = &sc->host.ios;
1556 cts = &ccb->cts.proto_specific.mmc;
1557 new_ios = &cts->ios;
1559 /* Update only requested fields */
1560 if (cts->ios_valid & MMC_CLK) {
1561 ios->clock = new_ios->clock;
1563 device_printf(sc->dev, "Clock => %d\n", ios->clock);
1565 if (cts->ios_valid & MMC_VDD) {
1566 ios->vdd = new_ios->vdd;
1568 device_printf(sc->dev, "VDD => %d\n", ios->vdd);
1570 if (cts->ios_valid & MMC_CS) {
1571 ios->chip_select = new_ios->chip_select;
1573 device_printf(sc->dev, "CS => %d\n", ios->chip_select);
1575 if (cts->ios_valid & MMC_BW) {
1576 ios->bus_width = new_ios->bus_width;
1578 device_printf(sc->dev, "Bus width => %d\n", ios->bus_width);
1580 if (cts->ios_valid & MMC_PM) {
1581 ios->power_mode = new_ios->power_mode;
1583 device_printf(sc->dev, "Power mode => %d\n", ios->power_mode);
1585 if (cts->ios_valid & MMC_BT) {
1586 ios->timing = new_ios->timing;
1588 device_printf(sc->dev, "Timing => %d\n", ios->timing);
1590 if (cts->ios_valid & MMC_BM) {
1591 ios->bus_mode = new_ios->bus_mode;
1593 device_printf(sc->dev, "Bus mode => %d\n", ios->bus_mode);
1595 if (cts->ios_valid & MMC_VCCQ) {
1596 ios->vccq = new_ios->vccq;
1598 device_printf(sc->dev, "VCCQ => %d\n", ios->vccq);
1599 res = dwmmc_switch_vccq(sc->dev, NULL);
1600 device_printf(sc->dev, "VCCQ switch result: %d\n", res);
1603 return (dwmmc_update_ios(sc->dev, NULL));
1607 dwmmc_cam_request(struct dwmmc_softc *sc, union ccb *ccb)
1609 struct ccb_mmcio *mmcio;
1611 mmcio = &ccb->mmcio;
1616 if (__predict_false(bootverbose)) {
1617 device_printf(sc->dev, "CMD%u arg %#x flags %#x dlen %u dflags %#x\n",
1618 mmcio->cmd.opcode, mmcio->cmd.arg, mmcio->cmd.flags,
1619 mmcio->cmd.data != NULL ? (unsigned int) mmcio->cmd.data->len : 0,
1620 mmcio->cmd.data != NULL ? mmcio->cmd.data->flags: 0);
1623 if (mmcio->cmd.data != NULL) {
1624 if (mmcio->cmd.data->len == 0 || mmcio->cmd.data->flags == 0)
1625 panic("data->len = %d, data->flags = %d -- something is b0rked",
1626 (int)mmcio->cmd.data->len, mmcio->cmd.data->flags);
1628 if (sc->ccb != NULL) {
1629 device_printf(sc->dev, "Controller still has an active command\n");
1634 dwmmc_request(sc->dev, NULL, NULL);
1640 static device_method_t dwmmc_methods[] = {
1642 DEVMETHOD(bus_read_ivar, dwmmc_read_ivar),
1643 DEVMETHOD(bus_write_ivar, dwmmc_write_ivar),
1646 DEVMETHOD(mmcbr_update_ios, dwmmc_update_ios),
1647 DEVMETHOD(mmcbr_request, dwmmc_request),
1648 DEVMETHOD(mmcbr_get_ro, dwmmc_get_ro),
1649 DEVMETHOD(mmcbr_acquire_host, dwmmc_acquire_host),
1650 DEVMETHOD(mmcbr_release_host, dwmmc_release_host),
1655 DEFINE_CLASS_0(dwmmc, dwmmc_driver, dwmmc_methods,
1656 sizeof(struct dwmmc_softc));