1114b4164SWarner Losh /*- 2114b4164SWarner Losh * Copyright (c) 2006 Bernd Walter. All rights reserved. 3114b4164SWarner Losh * Copyright (c) 2006 M. Warner Losh. All rights reserved. 4114b4164SWarner Losh * 5114b4164SWarner Losh * Redistribution and use in source and binary forms, with or without 6114b4164SWarner Losh * modification, are permitted provided that the following conditions 7114b4164SWarner Losh * are met: 8114b4164SWarner Losh * 1. Redistributions of source code must retain the above copyright 9114b4164SWarner Losh * notice, this list of conditions and the following disclaimer. 10114b4164SWarner Losh * 2. Redistributions in binary form must reproduce the above copyright 11114b4164SWarner Losh * notice, this list of conditions and the following disclaimer in the 12114b4164SWarner Losh * documentation and/or other materials provided with the distribution. 13114b4164SWarner Losh * 14114b4164SWarner Losh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15114b4164SWarner Losh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16114b4164SWarner Losh * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17114b4164SWarner Losh * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18114b4164SWarner Losh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19114b4164SWarner Losh * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20114b4164SWarner Losh * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21114b4164SWarner Losh * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22114b4164SWarner Losh * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23114b4164SWarner Losh * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2414eced72SWarner Losh * 2514eced72SWarner Losh * Portions of this software may have been developed with reference to 2614eced72SWarner Losh * the SD Simplified Specification. The following disclaimer may apply: 2714eced72SWarner Losh * 2814eced72SWarner Losh * The following conditions apply to the release of the simplified 2914eced72SWarner Losh * specification ("Simplified Specification") by the SD Card Association and 3014eced72SWarner Losh * the SD Group. The Simplified Specification is a subset of the complete SD 3114eced72SWarner Losh * Specification which is owned by the SD Card Association and the SD 3214eced72SWarner Losh * Group. This Simplified Specification is provided on a non-confidential 3314eced72SWarner Losh * basis subject to the disclaimers below. Any implementation of the 3414eced72SWarner Losh * Simplified Specification may require a license from the SD Card 3514eced72SWarner Losh * Association, SD Group, SD-3C LLC or other third parties. 3614eced72SWarner Losh * 3714eced72SWarner Losh * Disclaimers: 3814eced72SWarner Losh * 3914eced72SWarner Losh * The information contained in the Simplified Specification is presented only 4014eced72SWarner Losh * as a standard specification for SD Cards and SD Host/Ancillary products and 4114eced72SWarner Losh * is provided "AS-IS" without any representations or warranties of any 4214eced72SWarner Losh * kind. No responsibility is assumed by the SD Group, SD-3C LLC or the SD 4314eced72SWarner Losh * Card Association for any damages, any infringements of patents or other 4414eced72SWarner Losh * right of the SD Group, SD-3C LLC, the SD Card Association or any third 4514eced72SWarner Losh * parties, which may result from its use. No license is granted by 4614eced72SWarner Losh * implication, estoppel or otherwise under any patent or other rights of the 4714eced72SWarner Losh * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing 4814eced72SWarner Losh * herein shall be construed as an obligation by the SD Group, the SD-3C LLC 4914eced72SWarner Losh * or the SD Card Association to disclose or distribute any technical 5014eced72SWarner Losh * information, know-how or other confidential information to any third party. 51114b4164SWarner Losh */ 52114b4164SWarner Losh 53114b4164SWarner Losh #include <sys/cdefs.h> 54114b4164SWarner Losh __FBSDID("$FreeBSD$"); 55114b4164SWarner Losh 56114b4164SWarner Losh #include <sys/param.h> 57114b4164SWarner Losh #include <sys/systm.h> 58114b4164SWarner Losh #include <sys/kernel.h> 59114b4164SWarner Losh #include <sys/malloc.h> 60114b4164SWarner Losh #include <sys/lock.h> 61114b4164SWarner Losh #include <sys/module.h> 62114b4164SWarner Losh #include <sys/mutex.h> 63114b4164SWarner Losh #include <sys/bus.h> 64114b4164SWarner Losh 65114b4164SWarner Losh #include <dev/mmc/mmcreg.h> 66114b4164SWarner Losh #include <dev/mmc/mmcbrvar.h> 67114b4164SWarner Losh #include <dev/mmc/mmcvar.h> 68114b4164SWarner Losh #include "mmcbr_if.h" 69114b4164SWarner Losh #include "mmcbus_if.h" 70114b4164SWarner Losh 71114b4164SWarner Losh struct mmc_softc { 72114b4164SWarner Losh device_t dev; 73114b4164SWarner Losh struct mtx sc_mtx; 74114b4164SWarner Losh struct intr_config_hook config_intrhook; 75114b4164SWarner Losh device_t owner; 76114b4164SWarner Losh uint32_t last_rca; 77114b4164SWarner Losh }; 78114b4164SWarner Losh 79114b4164SWarner Losh /* 80114b4164SWarner Losh * Per-card data 81114b4164SWarner Losh */ 82114b4164SWarner Losh struct mmc_ivars { 83114b4164SWarner Losh uint32_t raw_cid[4]; /* Raw bits of the CID */ 84114b4164SWarner Losh uint32_t raw_csd[4]; /* Raw bits of the CSD */ 85114b4164SWarner Losh uint16_t rca; 86114b4164SWarner Losh enum mmc_card_mode mode; 87114b4164SWarner Losh struct mmc_cid cid; /* cid decoded */ 88114b4164SWarner Losh struct mmc_csd csd; /* csd decoded */ 8940fab6e7SWarner Losh u_char read_only; /* True when the device is read-only */ 90114b4164SWarner Losh }; 91114b4164SWarner Losh 92114b4164SWarner Losh #define CMD_RETRIES 3 93114b4164SWarner Losh 94114b4164SWarner Losh /* bus entry points */ 95114b4164SWarner Losh static int mmc_probe(device_t dev); 96114b4164SWarner Losh static int mmc_attach(device_t dev); 97114b4164SWarner Losh static int mmc_detach(device_t dev); 98114b4164SWarner Losh 99114b4164SWarner Losh #define MMC_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 100114b4164SWarner Losh #define MMC_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 101114b4164SWarner Losh #define MMC_LOCK_INIT(_sc) \ 102114b4164SWarner Losh mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->dev), \ 103114b4164SWarner Losh "mmc", MTX_DEF) 104114b4164SWarner Losh #define MMC_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx); 105114b4164SWarner Losh #define MMC_ASSERT_LOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED); 106114b4164SWarner Losh #define MMC_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED); 107114b4164SWarner Losh 108114b4164SWarner Losh static void mmc_delayed_attach(void *); 109114b4164SWarner Losh static int mmc_wait_for_cmd(struct mmc_softc *sc, struct mmc_command *cmd, 110114b4164SWarner Losh int retries); 111114b4164SWarner Losh static int mmc_wait_for_command(struct mmc_softc *sc, uint32_t opcode, 112114b4164SWarner Losh uint32_t arg, uint32_t flags, uint32_t *resp, int retries); 113114b4164SWarner Losh 114114b4164SWarner Losh static void 115114b4164SWarner Losh mmc_ms_delay(int ms) 116114b4164SWarner Losh { 117114b4164SWarner Losh DELAY(1000 * ms); /* XXX BAD */ 118114b4164SWarner Losh } 119114b4164SWarner Losh 120114b4164SWarner Losh static int 121114b4164SWarner Losh mmc_probe(device_t dev) 122114b4164SWarner Losh { 123114b4164SWarner Losh 1242703cdbbSWarner Losh device_set_desc(dev, "MMC/SD bus"); 125114b4164SWarner Losh return (0); 126114b4164SWarner Losh } 127114b4164SWarner Losh 128114b4164SWarner Losh static int 129114b4164SWarner Losh mmc_attach(device_t dev) 130114b4164SWarner Losh { 131114b4164SWarner Losh struct mmc_softc *sc; 132114b4164SWarner Losh 133114b4164SWarner Losh sc = device_get_softc(dev); 134114b4164SWarner Losh sc->dev = dev; 135114b4164SWarner Losh MMC_LOCK_INIT(sc); 136114b4164SWarner Losh 137114b4164SWarner Losh /* We'll probe and attach our children later, but before / mount */ 138114b4164SWarner Losh sc->config_intrhook.ich_func = mmc_delayed_attach; 139114b4164SWarner Losh sc->config_intrhook.ich_arg = sc; 140114b4164SWarner Losh if (config_intrhook_establish(&sc->config_intrhook) != 0) 141114b4164SWarner Losh device_printf(dev, "config_intrhook_establish failed\n"); 142114b4164SWarner Losh return (0); 143114b4164SWarner Losh } 144114b4164SWarner Losh 145114b4164SWarner Losh static int 146114b4164SWarner Losh mmc_detach(device_t dev) 147114b4164SWarner Losh { 1480e1466acSWarner Losh struct mmc_softc *sc = device_get_softc(dev); 1490e1466acSWarner Losh device_t *kids; 1500e1466acSWarner Losh int i, nkid; 1510e1466acSWarner Losh 1520e1466acSWarner Losh /* kill children [ph33r]. -sorbo */ 1530e1466acSWarner Losh if (device_get_children(sc->dev, &kids, &nkid) != 0) 1540e1466acSWarner Losh return 0; 1550e1466acSWarner Losh for (i = 0; i < nkid; i++) { 1560e1466acSWarner Losh device_t kid = kids[i]; 1570e1466acSWarner Losh void *ivar = device_get_ivars(kid); 1580e1466acSWarner Losh 1590e1466acSWarner Losh device_detach(kid); 1600e1466acSWarner Losh device_delete_child(sc->dev, kid); 1610e1466acSWarner Losh free(ivar, M_DEVBUF); 1620e1466acSWarner Losh } 1630e1466acSWarner Losh free(kids, M_TEMP); 1640e1466acSWarner Losh 1650e1466acSWarner Losh MMC_LOCK_DESTROY(sc); 1660e1466acSWarner Losh 1670e1466acSWarner Losh return 0; 168114b4164SWarner Losh } 169114b4164SWarner Losh 170114b4164SWarner Losh static int 171114b4164SWarner Losh mmc_acquire_bus(device_t busdev, device_t dev) 172114b4164SWarner Losh { 173114b4164SWarner Losh struct mmc_softc *sc; 174114b4164SWarner Losh int err; 175114b4164SWarner Losh int rca; 176114b4164SWarner Losh 177114b4164SWarner Losh err = MMCBR_ACQUIRE_HOST(device_get_parent(busdev), dev); 178114b4164SWarner Losh if (err) 179114b4164SWarner Losh return (err); 180114b4164SWarner Losh sc = device_get_softc(busdev); 181114b4164SWarner Losh MMC_LOCK(sc); 182114b4164SWarner Losh if (sc->owner) 183114b4164SWarner Losh panic("mmc: host bridge didn't seralize us."); 184114b4164SWarner Losh sc->owner = dev; 185114b4164SWarner Losh MMC_UNLOCK(sc); 186114b4164SWarner Losh 187114b4164SWarner Losh if (busdev != dev) { 188114b4164SWarner Losh // Keep track of the last rca that we've selected. If 189114b4164SWarner Losh // we're asked to do it again, don't. We never unselect 190114b4164SWarner Losh // unless the bus code itself wants the mmc bus. 191114b4164SWarner Losh rca = mmc_get_rca(dev); 192114b4164SWarner Losh if (sc->last_rca != rca) { 193114b4164SWarner Losh mmc_wait_for_command(sc, MMC_SELECT_CARD, rca << 16, 194114b4164SWarner Losh MMC_RSP_R1 | MMC_CMD_AC, NULL, CMD_RETRIES); 195114b4164SWarner Losh sc->last_rca = rca; 196114b4164SWarner Losh } 197114b4164SWarner Losh // XXX should set bus width here? 198114b4164SWarner Losh } else { 199114b4164SWarner Losh // If there's a card selected, stand down. 200114b4164SWarner Losh if (sc->last_rca != 0) { 201114b4164SWarner Losh mmc_wait_for_command(sc, MMC_SELECT_CARD, 0, 202114b4164SWarner Losh MMC_RSP_R1 | MMC_CMD_AC, NULL, CMD_RETRIES); 203114b4164SWarner Losh sc->last_rca = 0; 204114b4164SWarner Losh } 205114b4164SWarner Losh // XXX should set bus width here? 206114b4164SWarner Losh } 207114b4164SWarner Losh 208114b4164SWarner Losh return (0); 209114b4164SWarner Losh } 210114b4164SWarner Losh 211114b4164SWarner Losh static int 212114b4164SWarner Losh mmc_release_bus(device_t busdev, device_t dev) 213114b4164SWarner Losh { 214114b4164SWarner Losh struct mmc_softc *sc; 215114b4164SWarner Losh int err; 216114b4164SWarner Losh 217114b4164SWarner Losh sc = device_get_softc(busdev); 218114b4164SWarner Losh 219114b4164SWarner Losh MMC_LOCK(sc); 220114b4164SWarner Losh if (!sc->owner) 221114b4164SWarner Losh panic("mmc: releasing unowned bus."); 222114b4164SWarner Losh if (sc->owner != dev) 223114b4164SWarner Losh panic("mmc: you don't own the bus. game over."); 224114b4164SWarner Losh MMC_UNLOCK(sc); 225114b4164SWarner Losh err = MMCBR_RELEASE_HOST(device_get_parent(busdev), dev); 226114b4164SWarner Losh if (err) 227114b4164SWarner Losh return (err); 228114b4164SWarner Losh MMC_LOCK(sc); 229114b4164SWarner Losh sc->owner = NULL; 230114b4164SWarner Losh MMC_UNLOCK(sc); 231114b4164SWarner Losh return (0); 232114b4164SWarner Losh } 233114b4164SWarner Losh 234114b4164SWarner Losh static void 235114b4164SWarner Losh mmc_rescan_cards(struct mmc_softc *sc) 236114b4164SWarner Losh { 237114b4164SWarner Losh /* XXX: Look at the children and see if they respond to status */ 238114b4164SWarner Losh } 239114b4164SWarner Losh 240114b4164SWarner Losh static uint32_t 241114b4164SWarner Losh mmc_select_vdd(struct mmc_softc *sc, uint32_t ocr) 242114b4164SWarner Losh { 2438aaa15e2SWarner Losh 2448aaa15e2SWarner Losh return ocr & MMC_OCR_VOLTAGE; 245114b4164SWarner Losh } 246114b4164SWarner Losh 247114b4164SWarner Losh static int 248114b4164SWarner Losh mmc_highest_voltage(uint32_t ocr) 249114b4164SWarner Losh { 250114b4164SWarner Losh int i; 251114b4164SWarner Losh 252114b4164SWarner Losh for (i = 30; i >= 0; i--) 253114b4164SWarner Losh if (ocr & (1 << i)) 254114b4164SWarner Losh return i; 255114b4164SWarner Losh return (-1); 256114b4164SWarner Losh } 257114b4164SWarner Losh 258114b4164SWarner Losh static void 259114b4164SWarner Losh mmc_wakeup(struct mmc_request *req) 260114b4164SWarner Losh { 261114b4164SWarner Losh struct mmc_softc *sc; 262114b4164SWarner Losh 263114b4164SWarner Losh // printf("Wakeup for req %p done_data %p\n", req, req->done_data); 264114b4164SWarner Losh sc = (struct mmc_softc *)req->done_data; 265114b4164SWarner Losh MMC_LOCK(sc); 266114b4164SWarner Losh req->flags |= MMC_REQ_DONE; 267114b4164SWarner Losh wakeup(req); 268114b4164SWarner Losh MMC_UNLOCK(sc); 269114b4164SWarner Losh } 270114b4164SWarner Losh 271114b4164SWarner Losh static int 272114b4164SWarner Losh mmc_wait_for_req(struct mmc_softc *sc, struct mmc_request *req) 273114b4164SWarner Losh { 274114b4164SWarner Losh int err; 275114b4164SWarner Losh 276114b4164SWarner Losh req->done = mmc_wakeup; 277114b4164SWarner Losh req->done_data = sc; 278114b4164SWarner Losh // printf("Submitting request %p sc %p\n", req, sc); 279114b4164SWarner Losh MMCBR_REQUEST(device_get_parent(sc->dev), sc->dev, req); 280114b4164SWarner Losh MMC_LOCK(sc); 281114b4164SWarner Losh do { 282114b4164SWarner Losh err = msleep(req, &sc->sc_mtx, PZERO | PCATCH, "mmcreq", 283114b4164SWarner Losh hz / 10); 284114b4164SWarner Losh } while (!(req->flags & MMC_REQ_DONE) && err == EAGAIN); 285114b4164SWarner Losh // printf("Request %p done with error %d\n", req, err); 286114b4164SWarner Losh MMC_UNLOCK(sc); 287114b4164SWarner Losh return (err); 288114b4164SWarner Losh } 289114b4164SWarner Losh 290114b4164SWarner Losh static int 291114b4164SWarner Losh mmc_wait_for_request(device_t brdev, device_t reqdev, struct mmc_request *req) 292114b4164SWarner Losh { 293114b4164SWarner Losh struct mmc_softc *sc = device_get_softc(brdev); 294114b4164SWarner Losh 295114b4164SWarner Losh return mmc_wait_for_req(sc, req); 296114b4164SWarner Losh } 297114b4164SWarner Losh 298114b4164SWarner Losh static int 299114b4164SWarner Losh mmc_wait_for_cmd(struct mmc_softc *sc, struct mmc_command *cmd, int retries) 300114b4164SWarner Losh { 301114b4164SWarner Losh struct mmc_request mreq; 302114b4164SWarner Losh 303114b4164SWarner Losh memset(&mreq, 0, sizeof(mreq)); 304114b4164SWarner Losh memset(cmd->resp, 0, sizeof(cmd->resp)); 305114b4164SWarner Losh cmd->retries = retries; 306114b4164SWarner Losh cmd->data = NULL; 307114b4164SWarner Losh mreq.cmd = cmd; 308114b4164SWarner Losh // printf("CMD: %x ARG %x\n", cmd->opcode, cmd->arg); 309114b4164SWarner Losh mmc_wait_for_req(sc, &mreq); 310114b4164SWarner Losh return (cmd->error); 311114b4164SWarner Losh } 312114b4164SWarner Losh 313114b4164SWarner Losh static int 314114b4164SWarner Losh mmc_wait_for_app_cmd(struct mmc_softc *sc, uint32_t rca, 315114b4164SWarner Losh struct mmc_command *cmd, int retries) 316114b4164SWarner Losh { 317114b4164SWarner Losh struct mmc_command appcmd; 318114b4164SWarner Losh int err = MMC_ERR_NONE, i; 319114b4164SWarner Losh 320114b4164SWarner Losh for (i = 0; i <= retries; i++) { 321114b4164SWarner Losh appcmd.opcode = MMC_APP_CMD; 322114b4164SWarner Losh appcmd.arg = rca << 16; 323114b4164SWarner Losh appcmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 324114b4164SWarner Losh mmc_wait_for_cmd(sc, &appcmd, 0); 325114b4164SWarner Losh err = appcmd.error; 326114b4164SWarner Losh if (err != MMC_ERR_NONE) 327114b4164SWarner Losh continue; 328114b4164SWarner Losh if (!(appcmd.resp[0] & R1_APP_CMD)) 329114b4164SWarner Losh return MMC_ERR_FAILED; 330114b4164SWarner Losh mmc_wait_for_cmd(sc, cmd, 0); 331114b4164SWarner Losh err = cmd->error; 332114b4164SWarner Losh if (err == MMC_ERR_NONE) 333114b4164SWarner Losh break; 334114b4164SWarner Losh } 335114b4164SWarner Losh return (err); 336114b4164SWarner Losh } 337114b4164SWarner Losh 338114b4164SWarner Losh static int 339114b4164SWarner Losh mmc_wait_for_command(struct mmc_softc *sc, uint32_t opcode, 340114b4164SWarner Losh uint32_t arg, uint32_t flags, uint32_t *resp, int retries) 341114b4164SWarner Losh { 342114b4164SWarner Losh struct mmc_command cmd; 343114b4164SWarner Losh int err; 344114b4164SWarner Losh 345114b4164SWarner Losh memset(&cmd, 0, sizeof(cmd)); 346114b4164SWarner Losh cmd.opcode = opcode; 347114b4164SWarner Losh cmd.arg = arg; 348114b4164SWarner Losh cmd.flags = flags; 349114b4164SWarner Losh err = mmc_wait_for_cmd(sc, &cmd, retries); 350114b4164SWarner Losh if (err) 351114b4164SWarner Losh return (err); 352114b4164SWarner Losh if (cmd.error) 353114b4164SWarner Losh return (cmd.error); 354114b4164SWarner Losh if (resp) { 355114b4164SWarner Losh if (flags & MMC_RSP_136) 356114b4164SWarner Losh memcpy(resp, cmd.resp, 4 * sizeof(uint32_t)); 357114b4164SWarner Losh else 358114b4164SWarner Losh *resp = cmd.resp[0]; 359114b4164SWarner Losh } 360114b4164SWarner Losh return (0); 361114b4164SWarner Losh } 362114b4164SWarner Losh 363114b4164SWarner Losh static void 364114b4164SWarner Losh mmc_idle_cards(struct mmc_softc *sc) 365114b4164SWarner Losh { 366114b4164SWarner Losh device_t dev; 367114b4164SWarner Losh struct mmc_command cmd; 368114b4164SWarner Losh 369114b4164SWarner Losh dev = sc->dev; 370114b4164SWarner Losh mmcbr_set_chip_select(dev, cs_high); 371114b4164SWarner Losh mmcbr_update_ios(dev); 372114b4164SWarner Losh mmc_ms_delay(1); 373114b4164SWarner Losh 374114b4164SWarner Losh memset(&cmd, 0, sizeof(cmd)); 375114b4164SWarner Losh cmd.opcode = MMC_GO_IDLE_STATE; 376114b4164SWarner Losh cmd.arg = 0; 377114b4164SWarner Losh cmd.flags = MMC_RSP_NONE | MMC_CMD_BC; 378114b4164SWarner Losh mmc_wait_for_cmd(sc, &cmd, 0); 379114b4164SWarner Losh mmc_ms_delay(1); 380114b4164SWarner Losh 381114b4164SWarner Losh mmcbr_set_chip_select(dev, cs_dontcare); 382114b4164SWarner Losh mmcbr_update_ios(dev); 383114b4164SWarner Losh mmc_ms_delay(1); 384114b4164SWarner Losh } 385114b4164SWarner Losh 386114b4164SWarner Losh static int 387114b4164SWarner Losh mmc_send_app_op_cond(struct mmc_softc *sc, uint32_t ocr, uint32_t *rocr) 388114b4164SWarner Losh { 389114b4164SWarner Losh struct mmc_command cmd; 390114b4164SWarner Losh int err = MMC_ERR_NONE, i; 391114b4164SWarner Losh 392114b4164SWarner Losh memset(&cmd, 0, sizeof(cmd)); 393114b4164SWarner Losh cmd.opcode = ACMD_SD_SEND_OP_COND; 394114b4164SWarner Losh cmd.arg = ocr; 395114b4164SWarner Losh cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR; 396114b4164SWarner Losh 3976634080bSWarner Losh for (i = 0; i < 100; i++) { 398114b4164SWarner Losh err = mmc_wait_for_app_cmd(sc, 0, &cmd, CMD_RETRIES); 399114b4164SWarner Losh if (err != MMC_ERR_NONE) 400114b4164SWarner Losh break; 401114b4164SWarner Losh if ((cmd.resp[0] & MMC_OCR_CARD_BUSY) || ocr == 0) 402114b4164SWarner Losh break; 403114b4164SWarner Losh err = MMC_ERR_TIMEOUT; 404114b4164SWarner Losh mmc_ms_delay(10); 405114b4164SWarner Losh } 406114b4164SWarner Losh if (rocr && err == MMC_ERR_NONE) 407114b4164SWarner Losh *rocr = cmd.resp[0]; 408114b4164SWarner Losh return err; 409114b4164SWarner Losh } 410114b4164SWarner Losh 411114b4164SWarner Losh static int 412114b4164SWarner Losh mmc_send_op_cond(struct mmc_softc *sc, uint32_t ocr, uint32_t *rocr) 413114b4164SWarner Losh { 414114b4164SWarner Losh struct mmc_command cmd; 415114b4164SWarner Losh int err = MMC_ERR_NONE, i; 416114b4164SWarner Losh 417114b4164SWarner Losh memset(&cmd, 0, sizeof(cmd)); 418114b4164SWarner Losh cmd.opcode = MMC_SEND_OP_COND; 419114b4164SWarner Losh cmd.arg = ocr; 420114b4164SWarner Losh cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR; 421114b4164SWarner Losh 422114b4164SWarner Losh for (i = 0; i < 100; i++) { 423114b4164SWarner Losh err = mmc_wait_for_cmd(sc, &cmd, CMD_RETRIES); 424114b4164SWarner Losh if (err != MMC_ERR_NONE) 425114b4164SWarner Losh break; 426114b4164SWarner Losh if ((cmd.resp[0] & MMC_OCR_CARD_BUSY) || ocr == 0) 427114b4164SWarner Losh break; 428114b4164SWarner Losh err = MMC_ERR_TIMEOUT; 429114b4164SWarner Losh mmc_ms_delay(10); 430114b4164SWarner Losh } 431114b4164SWarner Losh if (rocr && err == MMC_ERR_NONE) 432114b4164SWarner Losh *rocr = cmd.resp[0]; 433114b4164SWarner Losh return err; 434114b4164SWarner Losh } 435114b4164SWarner Losh 436114b4164SWarner Losh static void 437114b4164SWarner Losh mmc_power_up(struct mmc_softc *sc) 438114b4164SWarner Losh { 439114b4164SWarner Losh device_t dev; 440114b4164SWarner Losh 441114b4164SWarner Losh dev = sc->dev; 442114b4164SWarner Losh mmcbr_set_vdd(dev, mmc_highest_voltage(mmcbr_get_host_ocr(dev))); 443114b4164SWarner Losh mmcbr_set_bus_mode(dev, opendrain); 444114b4164SWarner Losh mmcbr_set_chip_select(dev, cs_dontcare); 445114b4164SWarner Losh mmcbr_set_bus_width(dev, bus_width_1); 446114b4164SWarner Losh mmcbr_set_power_mode(dev, power_up); 447114b4164SWarner Losh mmcbr_set_clock(dev, 0); 448114b4164SWarner Losh mmcbr_update_ios(dev); 449114b4164SWarner Losh mmc_ms_delay(1); 450114b4164SWarner Losh 451114b4164SWarner Losh mmcbr_set_clock(dev, mmcbr_get_f_min(sc->dev)); 452114b4164SWarner Losh mmcbr_set_power_mode(dev, power_on); 453114b4164SWarner Losh mmcbr_update_ios(dev); 454114b4164SWarner Losh mmc_ms_delay(2); 455114b4164SWarner Losh } 456114b4164SWarner Losh 457114b4164SWarner Losh // I wonder if the following is endian safe. 458114b4164SWarner Losh static uint32_t 459114b4164SWarner Losh mmc_get_bits(uint32_t *bits, int start, int size) 460114b4164SWarner Losh { 461114b4164SWarner Losh const int i = 3 - (start / 32); 462114b4164SWarner Losh const int shift = start & 31; 463114b4164SWarner Losh uint32_t retval = bits[i] >> shift; 464114b4164SWarner Losh if (size + shift > 32) 465114b4164SWarner Losh retval |= bits[i - 1] << (32 - shift); 466114b4164SWarner Losh return retval & ((1 << size) - 1); 467114b4164SWarner Losh } 468114b4164SWarner Losh 469114b4164SWarner Losh static void 470114b4164SWarner Losh mmc_decode_cid(int is_sd, uint32_t *raw_cid, struct mmc_cid *cid) 471114b4164SWarner Losh { 472114b4164SWarner Losh int i; 473114b4164SWarner Losh 474114b4164SWarner Losh memset(cid, 0, sizeof(*cid)); 475114b4164SWarner Losh if (is_sd) { 476114b4164SWarner Losh /* There's no version info, so we take it on faith */ 477114b4164SWarner Losh cid->mid = mmc_get_bits(raw_cid, 120, 8); 478114b4164SWarner Losh cid->oid = mmc_get_bits(raw_cid, 104, 16); 479114b4164SWarner Losh for (i = 0; i < 5; i++) 480114b4164SWarner Losh cid->pnm[i] = mmc_get_bits(raw_cid, 96 - i * 8, 8); 481114b4164SWarner Losh cid->prv = mmc_get_bits(raw_cid, 56, 8); 482114b4164SWarner Losh cid->psn = mmc_get_bits(raw_cid, 24, 32); 483114b4164SWarner Losh cid->mdt_year = mmc_get_bits(raw_cid, 12, 8) + 2001; 484114b4164SWarner Losh cid->mdt_month = mmc_get_bits(raw_cid, 8, 4); 485114b4164SWarner Losh } else { 486114b4164SWarner Losh // XXX write me 487114b4164SWarner Losh panic("write mmc cid decoder"); 488114b4164SWarner Losh } 489114b4164SWarner Losh } 490114b4164SWarner Losh 491114b4164SWarner Losh static const int exp[8] = { 492114b4164SWarner Losh 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000 493114b4164SWarner Losh }; 494114b4164SWarner Losh static const int mant[16] = { 495114b4164SWarner Losh 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 496114b4164SWarner Losh }; 497114b4164SWarner Losh static const int cur_min[8] = { 498114b4164SWarner Losh 500, 1000, 5000, 10000, 25000, 35000, 60000, 100000 499114b4164SWarner Losh }; 500114b4164SWarner Losh static const int cur_max[8] = { 501114b4164SWarner Losh 1000, 5000, 10000, 25000, 35000, 45000, 800000, 200000 502114b4164SWarner Losh }; 503114b4164SWarner Losh 504114b4164SWarner Losh static void 505114b4164SWarner Losh mmc_decode_csd(int is_sd, uint32_t *raw_csd, struct mmc_csd *csd) 506114b4164SWarner Losh { 507114b4164SWarner Losh int v; 508114b4164SWarner Losh int m; 509114b4164SWarner Losh int e; 510114b4164SWarner Losh 511114b4164SWarner Losh memset(csd, 0, sizeof(*csd)); 512114b4164SWarner Losh if (is_sd) { 513114b4164SWarner Losh csd->csd_structure = v = mmc_get_bits(raw_csd, 126, 2); 514114b4164SWarner Losh if (v == 0) { 515114b4164SWarner Losh m = mmc_get_bits(raw_csd, 115, 4); 516114b4164SWarner Losh e = mmc_get_bits(raw_csd, 112, 3); 517114b4164SWarner Losh csd->tacc = exp[e] * mant[m] + 9 / 10; 518114b4164SWarner Losh csd->nsac = mmc_get_bits(raw_csd, 104, 8) * 100; 519114b4164SWarner Losh m = mmc_get_bits(raw_csd, 99, 4); 520114b4164SWarner Losh e = mmc_get_bits(raw_csd, 96, 3); 521114b4164SWarner Losh csd->tran_speed = exp[e] * 10000 * mant[m]; 522114b4164SWarner Losh csd->ccc = mmc_get_bits(raw_csd, 84, 12); 523114b4164SWarner Losh csd->read_bl_len = 1 << mmc_get_bits(raw_csd, 80, 4); 524114b4164SWarner Losh csd->read_bl_partial = mmc_get_bits(raw_csd, 79, 1); 525114b4164SWarner Losh csd->write_blk_misalign = mmc_get_bits(raw_csd, 78, 1); 526114b4164SWarner Losh csd->read_blk_misalign = mmc_get_bits(raw_csd, 77, 1); 527114b4164SWarner Losh csd->dsr_imp = mmc_get_bits(raw_csd, 76, 1); 528114b4164SWarner Losh csd->vdd_r_curr_min = cur_min[mmc_get_bits(raw_csd, 59, 3)]; 529114b4164SWarner Losh csd->vdd_r_curr_max = cur_max[mmc_get_bits(raw_csd, 56, 3)]; 530114b4164SWarner Losh csd->vdd_w_curr_min = cur_min[mmc_get_bits(raw_csd, 53, 3)]; 531114b4164SWarner Losh csd->vdd_w_curr_max = cur_max[mmc_get_bits(raw_csd, 50, 3)]; 532114b4164SWarner Losh m = mmc_get_bits(raw_csd, 62, 12); 533114b4164SWarner Losh e = mmc_get_bits(raw_csd, 47, 3); 534114b4164SWarner Losh csd->capacity = ((1 + m) << (e + 2)) * csd->read_bl_len; 535114b4164SWarner Losh csd->erase_blk_en = mmc_get_bits(raw_csd, 46, 1); 536114b4164SWarner Losh csd->sector_size = mmc_get_bits(raw_csd, 39, 7); 537114b4164SWarner Losh csd->wp_grp_size = mmc_get_bits(raw_csd, 32, 7); 538114b4164SWarner Losh csd->wp_grp_enable = mmc_get_bits(raw_csd, 31, 1); 539114b4164SWarner Losh csd->r2w_factor = 1 << mmc_get_bits(raw_csd, 26, 3); 540114b4164SWarner Losh csd->write_bl_len = 1 << mmc_get_bits(raw_csd, 22, 4); 541114b4164SWarner Losh csd->write_bl_partial = mmc_get_bits(raw_csd, 21, 1); 542114b4164SWarner Losh } else if (v == 1) { 543114b4164SWarner Losh panic("Write SDHC CSD parser"); 544114b4164SWarner Losh } else 545114b4164SWarner Losh panic("unknown SD CSD version"); 546114b4164SWarner Losh } else { 547114b4164SWarner Losh panic("Write a MMC CSD parser"); 548114b4164SWarner Losh } 549114b4164SWarner Losh } 550114b4164SWarner Losh 551114b4164SWarner Losh static int 552114b4164SWarner Losh mmc_all_send_cid(struct mmc_softc *sc, uint32_t *rawcid) 553114b4164SWarner Losh { 554114b4164SWarner Losh struct mmc_command cmd; 555114b4164SWarner Losh int err; 556114b4164SWarner Losh 557114b4164SWarner Losh cmd.opcode = MMC_ALL_SEND_CID; 558114b4164SWarner Losh cmd.arg = 0; 559114b4164SWarner Losh cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR; 560114b4164SWarner Losh err = mmc_wait_for_cmd(sc, &cmd, 0); 561114b4164SWarner Losh memcpy(rawcid, cmd.resp, 4 * sizeof(uint32_t)); 562114b4164SWarner Losh return (err); 563114b4164SWarner Losh } 564114b4164SWarner Losh 565114b4164SWarner Losh static int 566114b4164SWarner Losh mmc_send_csd(struct mmc_softc *sc, uint16_t rca, uint32_t *rawcid) 567114b4164SWarner Losh { 568114b4164SWarner Losh struct mmc_command cmd; 569114b4164SWarner Losh int err; 570114b4164SWarner Losh 571114b4164SWarner Losh cmd.opcode = MMC_SEND_CSD; 572114b4164SWarner Losh cmd.arg = rca << 16; 573114b4164SWarner Losh cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR; 574114b4164SWarner Losh err = mmc_wait_for_cmd(sc, &cmd, 0); 575114b4164SWarner Losh memcpy(rawcid, cmd.resp, 4 * sizeof(uint32_t)); 576114b4164SWarner Losh return (err); 577114b4164SWarner Losh } 578114b4164SWarner Losh 579114b4164SWarner Losh static int 580114b4164SWarner Losh mmc_send_relative_addr(struct mmc_softc *sc, uint32_t *resp) 581114b4164SWarner Losh { 582114b4164SWarner Losh struct mmc_command cmd; 583114b4164SWarner Losh int err; 584114b4164SWarner Losh 585114b4164SWarner Losh cmd.opcode = SD_SEND_RELATIVE_ADDR; 586114b4164SWarner Losh cmd.arg = 0; 587114b4164SWarner Losh cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR; 588114b4164SWarner Losh err = mmc_wait_for_cmd(sc, &cmd, 0); 589114b4164SWarner Losh *resp = cmd.resp[0]; 590114b4164SWarner Losh return (err); 591114b4164SWarner Losh } 592114b4164SWarner Losh 593114b4164SWarner Losh static void 594114b4164SWarner Losh mmc_discover_cards(struct mmc_softc *sc) 595114b4164SWarner Losh { 596114b4164SWarner Losh struct mmc_ivars *ivar; 597114b4164SWarner Losh int err; 598114b4164SWarner Losh uint32_t resp; 599114b4164SWarner Losh device_t child; 600114b4164SWarner Losh 601114b4164SWarner Losh while (1) { 602114b4164SWarner Losh ivar = malloc(sizeof(struct mmc_ivars), M_DEVBUF, M_WAITOK); 6030e1466acSWarner Losh if (!ivar) 6040e1466acSWarner Losh return; 605114b4164SWarner Losh err = mmc_all_send_cid(sc, ivar->raw_cid); 606114b4164SWarner Losh if (err == MMC_ERR_TIMEOUT) 607114b4164SWarner Losh break; 608114b4164SWarner Losh if (err != MMC_ERR_NONE) { 609114b4164SWarner Losh printf("Error reading CID %d\n", err); 610114b4164SWarner Losh break; 611114b4164SWarner Losh } 612114b4164SWarner Losh if (mmcbr_get_mode(sc->dev) == mode_sd) { 613114b4164SWarner Losh ivar->mode = mode_sd; 614114b4164SWarner Losh mmc_decode_cid(1, ivar->raw_cid, &ivar->cid); 615114b4164SWarner Losh mmc_send_relative_addr(sc, &resp); 616114b4164SWarner Losh ivar->rca = resp >> 16; 61740fab6e7SWarner Losh if (mmcbr_get_ro(sc->dev)) 61840fab6e7SWarner Losh ivar->read_only = 1; 619114b4164SWarner Losh mmc_send_csd(sc, ivar->rca, ivar->raw_csd); 620114b4164SWarner Losh mmc_decode_csd(1, ivar->raw_csd, &ivar->csd); 6210e1466acSWarner Losh printf("SD CARD: %lld bytes\n", (long long) 6220e1466acSWarner Losh ivar->csd.capacity); 623114b4164SWarner Losh child = device_add_child(sc->dev, NULL, -1); 624114b4164SWarner Losh device_set_ivars(child, ivar); 6250e1466acSWarner Losh return; 626114b4164SWarner Losh } 627114b4164SWarner Losh panic("Write MMC card code here"); 628114b4164SWarner Losh } 6290e1466acSWarner Losh free(ivar, M_DEVBUF); 630114b4164SWarner Losh } 631114b4164SWarner Losh 632114b4164SWarner Losh static void 633114b4164SWarner Losh mmc_go_discovery(struct mmc_softc *sc) 634114b4164SWarner Losh { 635114b4164SWarner Losh uint32_t ocr; 636114b4164SWarner Losh device_t dev; 637114b4164SWarner Losh 638114b4164SWarner Losh dev = sc->dev; 639114b4164SWarner Losh if (mmcbr_get_power_mode(dev) != power_on) { 640114b4164SWarner Losh // First, try SD modes 641114b4164SWarner Losh mmcbr_set_mode(dev, mode_sd); 642114b4164SWarner Losh mmc_power_up(sc); 643114b4164SWarner Losh mmcbr_set_bus_mode(dev, pushpull); 644114b4164SWarner Losh mmc_idle_cards(sc); 645114b4164SWarner Losh if (mmc_send_app_op_cond(sc, 0, &ocr) != MMC_ERR_NONE) { 646114b4164SWarner Losh // Failed, try MMC 647114b4164SWarner Losh mmcbr_set_mode(dev, mode_mmc); 648114b4164SWarner Losh if (mmc_send_op_cond(sc, 0, &ocr) != MMC_ERR_NONE) 649114b4164SWarner Losh return; // Failed both, punt! XXX power down? 650114b4164SWarner Losh } 651114b4164SWarner Losh mmcbr_set_ocr(dev, mmc_select_vdd(sc, ocr)); 652114b4164SWarner Losh if (mmcbr_get_ocr(dev) != 0) 653114b4164SWarner Losh mmc_idle_cards(sc); 654114b4164SWarner Losh } else { 655114b4164SWarner Losh mmcbr_set_bus_mode(dev, opendrain); 656114b4164SWarner Losh mmcbr_set_clock(dev, mmcbr_get_f_min(dev)); 657114b4164SWarner Losh mmcbr_update_ios(dev); 658114b4164SWarner Losh // XXX recompute vdd based on new cards? 659114b4164SWarner Losh } 660114b4164SWarner Losh /* 661114b4164SWarner Losh * Make sure that we have a mutually agreeable voltage to at least 662114b4164SWarner Losh * one card on the bus. 663114b4164SWarner Losh */ 664114b4164SWarner Losh if (mmcbr_get_ocr(dev) == 0) 665114b4164SWarner Losh return; 666114b4164SWarner Losh /* 667114b4164SWarner Losh * Reselect the cards after we've idled them above. 668114b4164SWarner Losh */ 669114b4164SWarner Losh if (mmcbr_get_mode(dev) == mode_sd) 670114b4164SWarner Losh mmc_send_app_op_cond(sc, mmcbr_get_ocr(dev), NULL); 671114b4164SWarner Losh else 672114b4164SWarner Losh mmc_send_op_cond(sc, mmcbr_get_ocr(dev), NULL); 673114b4164SWarner Losh mmc_discover_cards(sc); 674114b4164SWarner Losh 675114b4164SWarner Losh mmcbr_set_bus_mode(dev, pushpull); 676114b4164SWarner Losh mmcbr_update_ios(dev); 677114b4164SWarner Losh bus_generic_attach(dev); 678114b4164SWarner Losh // mmc_update_children_sysctl(dev); 679114b4164SWarner Losh } 680114b4164SWarner Losh 681114b4164SWarner Losh static int 682114b4164SWarner Losh mmc_calculate_clock(struct mmc_softc *sc) 683114b4164SWarner Losh { 684114b4164SWarner Losh int max_dtr = 0; 685114b4164SWarner Losh int nkid, i, f_min, f_max; 686114b4164SWarner Losh device_t *kids; 687114b4164SWarner Losh 688114b4164SWarner Losh f_min = mmcbr_get_f_min(sc->dev); 689114b4164SWarner Losh f_max = mmcbr_get_f_max(sc->dev); 690114b4164SWarner Losh max_dtr = f_max; 691114b4164SWarner Losh if (device_get_children(sc->dev, &kids, &nkid) != 0) 692114b4164SWarner Losh panic("can't get children"); 693114b4164SWarner Losh for (i = 0; i < nkid; i++) 694114b4164SWarner Losh if (mmc_get_tran_speed(kids[i]) < max_dtr) 695114b4164SWarner Losh max_dtr = mmc_get_tran_speed(kids[i]); 696114b4164SWarner Losh free(kids, M_TEMP); 697114b4164SWarner Losh device_printf(sc->dev, "setting transfer rate to %d.%03dMHz\n", 698114b4164SWarner Losh max_dtr / 1000000, (max_dtr / 1000) % 1000); 699114b4164SWarner Losh return max_dtr; 700114b4164SWarner Losh } 701114b4164SWarner Losh 702114b4164SWarner Losh static void 703114b4164SWarner Losh mmc_scan(struct mmc_softc *sc) 704114b4164SWarner Losh { 705114b4164SWarner Losh device_t dev; 706114b4164SWarner Losh 707114b4164SWarner Losh dev = sc->dev; 708114b4164SWarner Losh mmc_acquire_bus(dev, dev); 709114b4164SWarner Losh 710114b4164SWarner Losh if (mmcbr_get_power_mode(dev) == power_on) 711114b4164SWarner Losh mmc_rescan_cards(sc); 712114b4164SWarner Losh mmc_go_discovery(sc); 713114b4164SWarner Losh mmcbr_set_clock(dev, mmc_calculate_clock(sc)); 714114b4164SWarner Losh mmcbr_update_ios(dev); 715114b4164SWarner Losh 716114b4164SWarner Losh mmc_release_bus(dev, dev); 717114b4164SWarner Losh // XXX probe/attach/detach children? 718114b4164SWarner Losh } 719114b4164SWarner Losh 720114b4164SWarner Losh static int 721114b4164SWarner Losh mmc_read_ivar(device_t bus, device_t child, int which, u_char *result) 722114b4164SWarner Losh { 723114b4164SWarner Losh struct mmc_ivars *ivar = device_get_ivars(child); 724114b4164SWarner Losh 725114b4164SWarner Losh switch (which) { 726114b4164SWarner Losh default: 727114b4164SWarner Losh return (EINVAL); 728114b4164SWarner Losh case MMC_IVAR_DSR_IMP: 729114b4164SWarner Losh *(int *)result = ivar->csd.dsr_imp; 730114b4164SWarner Losh break; 731114b4164SWarner Losh case MMC_IVAR_MEDIA_SIZE: 732114b4164SWarner Losh *(int *)result = ivar->csd.capacity; 733114b4164SWarner Losh break; 734114b4164SWarner Losh case MMC_IVAR_RCA: 735114b4164SWarner Losh *(int *)result = ivar->rca; 736114b4164SWarner Losh break; 737114b4164SWarner Losh case MMC_IVAR_SECTOR_SIZE: 738114b4164SWarner Losh *(int *)result = 512; 739114b4164SWarner Losh break; 740114b4164SWarner Losh case MMC_IVAR_TRAN_SPEED: 741114b4164SWarner Losh *(int *)result = ivar->csd.tran_speed; 742114b4164SWarner Losh break; 74340fab6e7SWarner Losh case MMC_IVAR_READ_ONLY: 74440fab6e7SWarner Losh *(int *)result = ivar->read_only; 74540fab6e7SWarner Losh break; 746114b4164SWarner Losh } 747114b4164SWarner Losh return (0); 748114b4164SWarner Losh } 749114b4164SWarner Losh 750114b4164SWarner Losh static int 751114b4164SWarner Losh mmc_write_ivar(device_t bus, device_t child, int which, uintptr_t value) 752114b4164SWarner Losh { 753114b4164SWarner Losh // None are writable ATM 754114b4164SWarner Losh switch (which) { 755114b4164SWarner Losh default: 756114b4164SWarner Losh return (EINVAL); 757114b4164SWarner Losh } 758114b4164SWarner Losh return (0); 759114b4164SWarner Losh } 760114b4164SWarner Losh 761114b4164SWarner Losh 762114b4164SWarner Losh static void 763114b4164SWarner Losh mmc_delayed_attach(void *xsc) 764114b4164SWarner Losh { 765114b4164SWarner Losh struct mmc_softc *sc = xsc; 766114b4164SWarner Losh 767114b4164SWarner Losh mmc_scan(sc); 768114b4164SWarner Losh config_intrhook_disestablish(&sc->config_intrhook); 769114b4164SWarner Losh } 770114b4164SWarner Losh 771114b4164SWarner Losh static device_method_t mmc_methods[] = { 772114b4164SWarner Losh /* device_if */ 773114b4164SWarner Losh DEVMETHOD(device_probe, mmc_probe), 774114b4164SWarner Losh DEVMETHOD(device_attach, mmc_attach), 775114b4164SWarner Losh DEVMETHOD(device_detach, mmc_detach), 776114b4164SWarner Losh 777114b4164SWarner Losh /* Bus interface */ 778114b4164SWarner Losh DEVMETHOD(bus_read_ivar, mmc_read_ivar), 779114b4164SWarner Losh DEVMETHOD(bus_write_ivar, mmc_write_ivar), 780114b4164SWarner Losh 781114b4164SWarner Losh /* MMC Bus interface */ 782114b4164SWarner Losh DEVMETHOD(mmcbus_wait_for_request, mmc_wait_for_request), 783114b4164SWarner Losh DEVMETHOD(mmcbus_acquire_bus, mmc_acquire_bus), 784114b4164SWarner Losh DEVMETHOD(mmcbus_release_bus, mmc_release_bus), 785114b4164SWarner Losh 786114b4164SWarner Losh {0, 0}, 787114b4164SWarner Losh }; 788114b4164SWarner Losh 789114b4164SWarner Losh static driver_t mmc_driver = { 790114b4164SWarner Losh "mmc", 791114b4164SWarner Losh mmc_methods, 792114b4164SWarner Losh sizeof(struct mmc_softc), 793114b4164SWarner Losh }; 794114b4164SWarner Losh static devclass_t mmc_devclass; 795114b4164SWarner Losh 796114b4164SWarner Losh 797114b4164SWarner Losh DRIVER_MODULE(mmc, at91_mci, mmc_driver, mmc_devclass, 0, 0); 7980e1466acSWarner Losh DRIVER_MODULE(mmc, sdh, mmc_driver, mmc_devclass, 0, 0); 799